Now let's say you want to write a regex that strips out all c comments from the given c file. The way I was thinking about is would be to use non greedy regex to strip out only non-embeeded comments first. And then do multiple passes to ensure you got all comments out./* this is a test * c file /* with an embedded comment */ * in the middle * */ int main(void) { int a; int b; }
But then the trick is, I know how to use something like this to do character negation:
That will match stuff like "abcjjjkkklllmmmdef" and make it "abcdef" but it would NOT work if there was a x or y or z in that inside part like "abcjjjkkkxlllmmmdef"$var =~ s/abc[^xyz]*?def//;
Now back to the comments in C source code. I can't use single character negation. I want to NOT have a two character patern in the middle part.
I've looked at things like negative lookahead or negative lookbehind, but just don't think that works either.
Any regex experts out there that can answer this puzzle?
NOTE: it should also not assume there are no stars in the embedded comment. Or in other words, it should handle this too:
/* this is a test * c file /* with an embedded * multiline * comment */ * in the middle * */ int main(void) { int a; int b; }
Justin Eltoft
"If at all god's gaze upon us falls, its with a mischievous grin, look at him" -- Dave Matthews
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |