From perlfaq6 "How to use regex to erase style style comments from a file?":
Although this can really be done, it is much more complicated than you think. For example, this one line
perl -0777 -pe 's{/\*.*?\*/}{}gs' foo.c
, . , C, , , . , , .
$/ = undef;
$_ = <>;
s#/\*[^*]*\*+([^/*][^*]*\*+)*/|("(\\.|[^"\\])*"|'(\\.|[^'\\])*'|.[^/"'\\]*)#defined $2 ? $2 : ""#gse;
print;
, , /x, . , .
s{
/\*
[^*]*\*+
(
[^/*][^*]*\*+
)*
/
|
(
" ## Start of " ... " string
(
\\. ## Escaped char
| ## OR
[^"\\]
)*
" ## End of " ... " string
| ## OR
' ## Start of ' ... ' string
(
\\. ## Escaped char
| ## OR
[^'\\] ## Non '\
)*
' ## End of ' ... ' string
| ## OR
. ## Anything other char
[^/"'\\]* ## Chars which doesn't start a comment, string or escape
)
}{defined $2 ? $2 : ""}gxse;
++, , :
s#/\*[^*]*\*+([^/*][^*]*\*+)*/|//([^\\]|[^\n][\n]?)*?\n|("(\\.|[^"\\])*"|'(\\.|[^'\\])*'|.[^/"'\\]*)#defined $3 ? $3 : ""#gse;