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) + '*'