rred - A perl regular expression debugging tool
rred is an interactive command line interface for experimenting with regular expressions. Given a regular expression and a text string, it shows how the regular expression (and any parenthesised subexpressions) matches against the text string.
The text string, expression and match modifiers can be modified interactively. The interface uses the Term::ReadLine library for input, so if you have a package like Term::ReadLine::Gnu installed, you'll have all the comforts of command line history and editing. If not, you'll get a less glamorous but adequate stub interface (see the Term::ReadLine manpage for details).
Input lines are of the form
<command>[argument]
Where <command> is one of:
Both the text string and the regular expression entered are executed in a perl 'eval' statement (see perlfunc).
The text string is wrapped in the quote characters specified with the 'q' command.
The expression is evaluated using the m// operator (see perlop), with the modifiers and delimiters specified using the 'm' and 'd' commands.
If either the text string or regular expression match produces a runtime error, it will be caught and displayed.
After each command, perl code for the pattern match being tested is printed.
If both the text and expression have been set, the code will be executed. If the expression matches against the text, a line containing the text will be printed, followed by one line for each of $&, $1, $2, etc. that is defined (where $& is the entire match, $1 is the first subexpression, $2 the second, etc.).
The values of $&, $1, $2, etc. are indicated by '^' symbols under the corresponding part of the text. Zero-length matches are indicated by a '/\' around the correct position.
If the modifiers value includes a 'g', the above will be repeated if there are multiple matches.
New bug reports and patches are welcome.
Written by Hannes Reich (hannesATskynet.ie). Inspired by the nifty regular expression tool in ActiveState's Komodo IDE.
This code is in the public domain. Permission is granted to anyone to use it for any purpose.
perlre, perlop, the Term::ReadLine manpage