Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: need regex help to strip things like embedded C comments

by brian_d_foy (Abbot)
on Jul 22, 2007 at 00:44 UTC ( [id://628053]=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://628053]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (3)
As of 2024-04-25 07:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found