note
kejohm
<p>You could also try [mod://YAPE::Regex::Explain]. Thanks to [Toolic] for suggesting this module in a previous post. Here is an example using one of your regexes:</p>
<code>
#!perl
use strict;
use warnings;
use YAPE::Regex::Explain;
print YAPE::Regex::Explain->new(qr/(?:\w+\s+fish\s+){2}(\w+)\s+fish/i)->explain();
__END__
The regular expression:
(?i-msx:(?:\w+\s+fish\s+){2}(\w+)\s+fish)
matches as follows:
NODE EXPLANATION
----------------------------------------------------------------------
(?i-msx: group, but do not capture (case-insensitive)
(with ^ and $ matching normally) (with . not
matching \n) (matching whitespace and #
normally):
----------------------------------------------------------------------
(?: group, but do not capture (2 times):
----------------------------------------------------------------------
\w+ word characters (a-z, A-Z, 0-9, _) (1 or
more times (matching the most amount
possible))
----------------------------------------------------------------------
\s+ whitespace (\n, \r, \t, \f, and " ") (1
or more times (matching the most amount
possible))
----------------------------------------------------------------------
fish 'fish'
----------------------------------------------------------------------
\s+ whitespace (\n, \r, \t, \f, and " ") (1
or more times (matching the most amount
possible))
----------------------------------------------------------------------
){2} end of grouping
----------------------------------------------------------------------
( group and capture to \1:
----------------------------------------------------------------------
\w+ word characters (a-z, A-Z, 0-9, _) (1 or
more times (matching the most amount
possible))
----------------------------------------------------------------------
) end of \1
----------------------------------------------------------------------
\s+ whitespace (\n, \r, \t, \f, and " ") (1 or
more times (matching the most amount
possible))
----------------------------------------------------------------------
fish 'fish'
----------------------------------------------------------------------
) end of grouping
----------------------------------------------------------------------
</code>
<p><small><b>Update:</b> Link fixed.</small></p>
854220
854220