not the way ... (was Re: Want a way to strip comments from a)

Leo de Wit leo at philmds.UUCP
Sat Mar 18 05:38:47 AEST 1989


In article <981 at philmds.UUCP> leo at philmds.UUCP (Leo de Wit) writes:
|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).

Shame on me. That it works is merely a coincidence (put a * in a
comment and see it fail). \1 matches the previous string matching a
\( \) expression, not the expression itself.  And since sed doesn't
like \( \)* type expressions, this would be hard to do in one regexpr.
Can it be proven to be impossible (that is, deleting the comments
with one sed command - multi-line comments not considered) ?

   Leo.



More information about the Comp.lang.c mailing list