Path: utzoo!attcan!uunet!mcvax!hp4nl!philmds!leo From: leo@philmds.UUCP (Leo de Wit) Newsgroups: comp.lang.c Subject: Re: not the way ... (was Re: Want a way to strip comments from a) Message-ID: <981@philmds.UUCP> Date: 17 Mar 89 19:06:06 GMT References: <7150@siemens.UUCP> <9900010@bradley> <4221@omepd.UUCP> Reply-To: leo@philmds.UUCP (Leo de Wit) Organization: Philips I&E DTS Eindhoven Lines: 25 In article <4221@omepd.UUCP> merlyn@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.