Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!ucsd!chem.ucsd.edu!tps From: tps@chem.ucsd.edu (Tom Stockfisch) Newsgroups: comp.lang.c Subject: Re: regex for C comments Message-ID: <502@chem.ucsd.EDU> Date: 12 Jul 89 01:07:26 GMT References: <19365@paris.ics.uci.edu> Reply-To: tps@chem.ucsd.edu (Tom Stockfisch) Distribution: na Organization: Chemistry Dept, UC San Diego Lines: 23 In article <19365@paris.ics.uci.edu> schmidt@zola.ics.uci.edu (Doug Schmidt) writes: >In their book ``Introduction to Compiler Construction with UNIX,'' >Schreiner and Friedman provide the following LEX regular expression >for recognizing C comments: >"/*""/"*([^*/]|[^*]"/"|"*"[^/])*"*"*"*/" This expression fails on each of the following: /*****//hello world */ /* hello /* /* world */ So, who has the shortest single LEX expression that correctly matches C comments -- ignoring string and character constants, and disallowing start conditions? Mine is "/*"\/*([^/]|{[^*/]\/+})*"*/" -- || Tom Stockfisch, UCSD Chemistry tps@chem.ucsd.edu