It is one of the things I consider to be a bug in Perl's regex engine. Zero-width matches can cause Perl to consider multiple matches starting at the same point. Perl eventually rejects identical matches in order to prevent an infinite loop. Your (?{ block catches Perl given a go at trying to match something different by trying the match a second time at each starting point.
You can work around this simply enough:
#!perl -wl use strict; my $s = 'abcd'; my @pairs1 = $s =~ m{ (?= (..)).? (?{ printf qq{ '$^N'} }) }xmsg; # ^^ print ''; printf qq{ :$_:} for @pairs1; print ''; my @pairs2 = $s =~ m{ (?= (..) (?{ printf qq{ '$^N'} })).? }xmsg; # ^^ print ''; printf qq{ :$_:} for @pairs2; print ''; __END__ 'ab' 'bc' 'cd' :ab: :bc: :cd: 'ab' 'bc' 'cd' :ab: :bc: :cd:
(Update: Pasted the wrong code for a few seconds.)
- tye
In reply to Re: Regex: Overlapping Matches: Double Execution of Eval-ed Code (pos==pos && len!=len)
by tye
in thread Regex: Overlapping Matches: Double Execution of Eval-ed Code
by AnomalousMonk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |