Reputation: 353
I am using a perl one liner to remove the comments from from a C file, but it also removes the lines which have an asterik(*) in between words, for eg
static void *
Here in the one liner I am using:
'perl -0777 -pe ''s{/\*.*?\*/}{}gs'' ' sourceFile ' > ' destFile
Could anyone please suggest?
Thanks
Upvotes: 0
Views: 663
Reputation: 763
Your regex works for me. I just corrected your quoting, I don't know if your are using it like that, or it was a copy&paste artefact.
perl -0777 -pe 's{/\*.*?\*/}{}gs' sourceFile.c >destFile.c
(I am using bash
on linux.)
Try it on Ideone.
Upvotes: 0
Reputation: 87
This question is answered in the perlfaq.
"How do I use a regular expression to strip C style comments from a file?"
Upvotes: 2
Reputation: 7361
maybe something like this:
s{/\*((?!\*/).)*\*/}gs
"Look for /*
, look ahead to not see the */
sequence and eat one character, repeat the look-and-eat up until */
"
Be aware, however, that since the comments can be nested or the /* */
enclosed in quotation marks, you can never reliably parse them out with regular expressions.
Upvotes: 0