Re: RegExp to match against RegExp's

"Russ Cox" <>
5 Mar 2007 03:12:29 -0500

          From comp.compilers

Related articles
RegExp to match against RegExp's (whiskey) (2007-03-01)
Re: RegExp to match against RegExp's (Joel C. Salomon) (2007-03-03)
Re: RegExp to match against RegExp's (Russ Cox) (2007-03-05)
Re: RegExp to match against RegExp's (Thomas Dickey) (2007-03-08)
Re: RegExp to match against RegExp's (whiskey) (2007-03-14)
| List of all articles for this month |

From: "Russ Cox" <>
Newsgroups: comp.compilers
Date: 5 Mar 2007 03:12:29 -0500
Organization: Compilers Central
References: 07-03-003
Keywords: lex
Posted-Date: 05 Mar 2007 03:12:29 EST

If all you want to do is match something between slashes, regardless
of whether it is a well-formed regular expression, you could, ignoring
escaping issues, use "/([^/\]|\.)*/", which matches a sequence of
non-slash characters or escape sequences between slashes. Escaping
that in the usual way gets you to the less readable $s =~
/\/([^\/\\]|\\.)*\//. The same trick is useful for extracting quoted
strings from, say, C programs -- just change the / to " in the

Verifying that something between slashes is a well-formed regular
expression is another problem, one that is not best approached using
regular expressions, even in languages like Perl where the so-called
regular expressions have been beefed up enough to make it possible.

Determining, for a given place in a Perl program text, whether a slash
begins a regular expression or is just a division operator, is yet
another problem, again not really something you'd want to solve with
regular expressions, though a few heuristics (like does it follow a
"~") would probably get you close enough.

The short answer is do something that works for your program or learn
how to make Perl just dump the regular expressions out of the source
program for you (I recall there being a Perl module or an option or
some way to do that). There is no clean solution.


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.