in reply to need regex help to strip things like embedded C comments

C doesn't have nested comments, and your code example doesn't compile (in gcc at least. Maybe you have some odd compiler). Are you trying to find the nested comments and remove them so you have compilable code? If so, you'll need to do a lot more work and probably use a parser.

For legal C comments, there is an answer in perlfaq6, " How do I use a regular expression to strip C style comments from a file", and it includes the regex from Jeffrey Friedl. If anyone has good information to add to that answer, send me the updates. :)

Good luck :)

Update: Correct perlfaq6 number, and, as ikegami notes, that FAQ deals with C comments, not nested comments. The OP said he had C source *shrug*

--
brian d foy <brian@stonehenge.com>
Subscribe to The Perl Review
  • Comment on Re: need regex help to strip things like embedded C comments

Replies are listed 'Best First'.
Re^2: need regex help to strip things like embedded C comments
by wind (Priest) on Jul 22, 2007 at 03:57 UTC
      The OP's comments are not C-style comments. C doesn't support nesting of comments, and neither does the code at the link you provided.