not the way ... (was Re: Want a way to strip comments from a)
Leo de Wit
leo at philmds.UUCP
Sat Mar 18 05:06:06 AEST 1989
In article <4221 at omepd.UUCP> merlyn at intelob.intel.com (Randal L. Schwartz @ Stonehenge) writes:
[]
|Nope. Just try it on the line:
|
| foo; bar; /* comment1 */ bletch; /* comment2 */
|
|'bletch;' disappears with the comments.
|
|The regexp that matches comments looks like (in egrep/lex notation):
|
| [/][*]([*]*[^*/])*[*]+[/]
|
|(I use [X] here instead of \X because I hate backslashes...).
|
|Sed and vi are not powerful enough to eat things like this in one
|regexp.
Sed is often underestimated; it IS powerful enough:
s/\/\*\([^*/]*\*\)\1*\///g
will eat the comments away just nicely (I'll leave the HOW as an
exercise for the reader).
Leo.
More information about the Comp.lang.c
mailing list