Don't forget about such tools as YAPE::Regex::Explain, where the synopsis in the POD provides this simple example:

use YAPE::Regex::Explain; my $exp = YAPE::Regex::Explain->new($REx)->explain;

In the above example, let $REx be your regular expression as a single-quoted string or a qr// object.

If you print $exp, you'll get a nice table explaining each subexpression within the regular expression.

That's probably one of the more powerful tools for me.

Here is an example output from YAPE::Regex::Explain, when invoked as follows:

perl -MYAPE::Regexp::Explain -e "print YAPE::Regex::Explain->new('\bte +st(?: more)\b$')->explain();"

And the output...

The regular expression: (?-imsx:\btest(?: more)\b$) matches as follows: NODE EXPLANATION ---------------------------------------------------------------------- (?-imsx: group, but do not capture (case-sensitive) (with ^ and $ matching normally) (with . not matching \n) (matching whitespace and # normally): ---------------------------------------------------------------------- \b the boundary between a word char (\w) and something that is not a word char ---------------------------------------------------------------------- test 'test' ---------------------------------------------------------------------- (?: group, but do not capture: ---------------------------------------------------------------------- more ' more' ---------------------------------------------------------------------- ) end of grouping ---------------------------------------------------------------------- \b the boundary between a word char (\w) and something that is not a word char ---------------------------------------------------------------------- $ before an optional \n, and the end of the string ---------------------------------------------------------------------- ) end of grouping ----------------------------------------------------------------------

Perl also provides the use re qw/debug/; pragma, which can be used like this:

#!/usr/bin/perl use re 'debug'; m/ \b test regexp \b /x;

When you execute that you'll get a sort of compilation version of the regular expression, which is sometimes helpful in seeing what's going on (or wrong). This is discussed in perldebug and perldebuguts.


Dave


In reply to Re: Regex Debugger? by davido
in thread Regex Debugger? by pileofrogs

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.