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
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.