[thelist] Regular expression to check if other regular expressions are valid

lustig at brandeis.edu lustig at brandeis.edu
Wed Jun 22 15:24:31 CDT 2005

> which is a valid regular expression with infinitely many positive
> lookaheads. I've forgotten the stuff with theory of large numbers etc,
> but hope that an interested can prove that it is impossible to match
> such a regex with a regex.

I definitely think that it is possible to create a regex to match other
regexes... I was going to try doing it myself but was wondering if someone
has done it already. THe reason why I think that it is possible, is because
there *is* a pattern to regular expressions. The PHP parser, for example,
knows when there is a syntax error in a regular expression, because it stops
parsing it and throws an error. There is no way to check a regular expression
to see if it does what you want it to do (besides doing a rigorous proof) but
there probably is a (ridiculously complex) regular expression which will
decide whether another regular expression is a valid regex.

My idea on this is that the regular expression would look something like this,
but more fleshed out:

(something to check beginning of regex) (something to check inside of regex)
(something to check end and modifiers)

the "something to check inside of regex" would look like this:

[(list of possible characters like \s\S\\s\\S\.\\. etc.)]*

and then just put that in a bunch of possible ways to organize a regex that
allows for nesting it in parentheses, etc.


More information about the thelist mailing list