Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!apple!oliveb!mipos3!omepd!merlyn From: merlyn@iwarp.intel.com (Randal Schwartz) Newsgroups: comp.lang.c Subject: Re: regex for C comments Message-ID: <4626@omepd.UUCP> Date: 10 Jul 89 19:03:09 GMT References: <19365@paris.ics.uci.edu> Sender: news@omepd.UUCP Reply-To: merlyn@iwarp.intel.com (Randal Schwartz) Distribution: na Organization: Stonehenge; netaccess via Intel, Hillsboro, Oregon, USA Lines: 35 In-reply-to: schmidt@zola.ics.uci.edu (Doug Schmidt) In article <19365@paris.ics.uci.edu>, schmidt@zola (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: | | ---------------------------------------- | "/*""/"*([^*/]|[^*]"/"|"*"[^/])*"*"*"*/" | ---------------------------------------- | | Ignoring the possibility of overflowing an internal LEX buffer, | does anyone know of any legal C comments that fail to match | with this regular expression? Try: /***/ (This one was easy. :-) The problem with this one is that "star" "not-slash" can match "star" "star" where the second star is sometimes the first star of the terminating "star" "slash" This is a common problem with these regex's. Now come on people, is this one of those "20 most commonly asked questions in comp.lang.c"? And who has the right answer? (Not me.... I screwed up last time... :-) Just another C hacker, -- /== Randal L. Schwartz, Stonehenge Consulting Services (503)777-0095 ====\ | on contract to Intel, Hillsboro, Oregon, USA | | merlyn@iwarp.intel.com ...!uunet!iwarp.intel.com!merlyn | \== Cute Quote: "Welcome to Oregon... Home of the California Raisins!" ==/