the answer (I hope!) (was Re: regex for C comments)

Randal Schwartz merlyn at iwarp.intel.com
Fri Jul 14 01:50:55 AEST 1989


In article <502 at chem.ucsd.EDU>, tps at chem (Tom Stockfisch) writes:
| So, who has the shortest single LEX expression that correctly
| matches C comments --
| ignoring string and character constants,
| and disallowing start conditions?
| 
| Mine is
| 
| 	"/*"\/*([^/]|{[^*/]\/+})*"*/"

What are these curly brace things?  They're not used in accordance
with V7 (the One True Unix :-) Lex.

OK, I'll toss my submission back in the ring, which I have tested (for
once... :-).

	"/*"("*"*[^*/]+|"/"+)*"*"+"/"

You could make it shorter by leaving off the two plus signs inside the
parens, but this is probably more efficient.

Ducking to avoid the onslaught of test cases,
-- 
/== Randal L. Schwartz, Stonehenge Consulting Services (503)777-0095 ====\
| on contract to Intel, Hillsboro, Oregon, USA                           |
| merlyn at iwarp.intel.com ...!uunet!iwarp.intel.com!merlyn	         |
\== Cute Quote: "Welcome to Oregon... Home of the California Raisins!" ==/



More information about the Comp.lang.c mailing list