in reply to Regex look ahead

Tanktalus provided an excellent decription of how the regular expression attempted to match your string. If you would like to experiment with the regex some more I recommend using YAPE::Regex::Explain to get english descriptions of how a given regular expression works. It's much easier to read than the output of use re 'debug'

use strict; use warnings; use YAPE::Regex::Explain; my $regex = qr/foo # Match starting at foo (?: # Complex expression: (?!baz) # make sure we're not at the beginning of baz . # accept any character )* # any number of times bar # and ending at bar /x; my $explanation = YAPE::Regex::Explain->new($regex)->explain; print $explanation;
Outputs:
The regular expression: (?x-ims:foo # Match starting at foo (?: # Complex expression: (?!baz) # make sure we're not at the beginning of baz . # accept any character )* # any number of times bar # and ending at bar ) matches as follows: NODE EXPLANATION ---------------------------------------------------------------------- (?x-ims: group, but do not capture (disregarding whitespace and comments) (case-sensitive) (with ^ and $ matching normally) (with . not matching \n): ---------------------------------------------------------------------- foo 'foo' ---------------------------------------------------------------------- (?: group, but do not capture (0 or more times (matching the most amount possible)): ---------------------------------------------------------------------- (?! look ahead to see if there is not: ---------------------------------------------------------------------- baz 'baz' ---------------------------------------------------------------------- ) end of look-ahead ---------------------------------------------------------------------- . any character except \n ---------------------------------------------------------------------- )* end of grouping ---------------------------------------------------------------------- bar 'bar' ---------------------------------------------------------------------- ) end of grouping ----------------------------------------------------------------------