I wrote a program to parse a simple regex so as to return a
string that would match the regex! I am very thrilled.
The code requires Perl 5.6. To test it, go to the following
URL:
http://www.pobox.com/~japhy/regexes/parseRE.
Update: the next version of this will appear as the
RegexParser module. It will offer functions for
finding a string to match a regex, and for doing its best at
reversing a regular expression.
The following is a (rather incomplete) list of known cool
features:
- supports alternation, character classes, etc. (and it
chooses the match randomly)
- supports backreferences (wow!)
- supports nested backreferences (double wow!)
The following is a (rather incomplete) list of known bugs:
- the ^ and $ anchors are there, but I
don't do anything with them, really (is this really a bug?)
- look-ahead and look-behind are not yet supported
- complex things like (?>...) and (??{...})
are obviously not supported
- the \b and \B assertions are not yet
supported (they will be supported soon)
- multi-line (the m modifier) support is not
yet available
- UPDATE: character classes are a bit buggy... I'm
working to fix this
- the code is kinda unreadable...
PLEASE try this puppy out. It took me all day to make this,
and I think it's damn cool. If you find a bug and it's not
on the abbreviated bug list, DON'T hesitate to email me about
it! My email address can be found on my web site and on my
home node.
$_="goto+F.print+chop;\n=yhpaj";F1:eval