NAME

rred - A perl regular expression debugging tool


DESCRIPTION

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).

COMMANDS

Input lines are of the form

 <command>[argument]

Where <command> is one of:

t
Specifies the remainder of the input as the text to match against.

e
Specifies the remainder of the input as the regular expression to test.

m
Specifies the remainder of the input as modifiers (zero or more of c, g, i, o, m, s, x) for the expression match. The modifiers value defaults to 'g'.

q
Sets the quote character to use arount the text. The default is '``' (double quote). This means that escape sequences can be used, and that the usual characters must be escaped.

d
Sets the delimiter for the expression. The default is '/'.

x
Quits the program (as will an EOF (ctrl-d) character).

EVALUATION

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.

OUTPUT

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.


BUGS

New bug reports and patches are welcome.


AUTHOR and CREDITS

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.


SEE ALSO

perlre, perlop, the Term::ReadLine manpage