Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Kill C style comments

by jweed (Chaplain)
on Mar 22, 2004 at 06:12 UTC ( [id://338569]=note: print w/replies, xml ) Need Help??


in reply to Kill C style comments

I highly suggest you pick up a copy of Jeff Friedl's "Mastering Regular Expressions", where this example is discussed in great length. The Final answer is:
s{(?:"(?:\\.|[^"\\])*")|(?:/\*[^*]*\*+(?:[^/*][^*]*\*+)*/)}{}g
Which nicely "unrolls the loop" for double-quote-aware comment removal. Pretty slick, huh? Check the book out ASAP!



Code is (almost) always untested.
http://www.justicepoetic.net/

Replies are listed 'Best First'.
Re: Re: Kill C style comments
by Anonymous Monk on Mar 22, 2004 at 18:04 UTC
    That still won't handle '/*' (single quotes) which is in fact valid C, equal to ('/' << 8) + '*'

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (6)
As of 2024-04-18 18:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found