develooper Front page | perl.perl5.porters | Postings from April 2007

Re: [perl #42289] Second Zero-Length Iterative Regexp Match Fails

Thread Previous
April 4, 2007 02:26
Re: [perl #42289] Second Zero-Length Iterative Regexp Match Fails
Message ID:
On 4/3/07, via RT Andri <> wrote:
> # New Ticket Created by  Andri
> # Please include the string:  [perl #42289]
> # in the subject line of all future correspondence about this issue.
> # <URL: >
> A zero-length match with \G seems not to match twice at the same position without doing pos()=pos() in the middle of those matches.
> Both \G(?=Welcome) and (?=\GWelcome) seem to not-match on my system.
> perl -le '$_="Welcome to Estonia!"; print "1. Matches" if /\G(?=W)/gc; print "2. Should match, but does not" if /\G(?=Wel)/gc; pos=pos; print "3. Now matches again" if /\G(?=Welcome)/gc'
> That's it. Hopefully not intended behaviour ^_^

Yes this is correct. There is logic in place to prevent two zero
length matches from occuring at the same place in a row. The second
time the start position will be forced forward one character before
matching. This baheviour prevents inifinte loops and also is behind
the scenes responsible for split // afair.

perl -Mre=debug -e "/just|another|perl|hacker/"

Thread Previous Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About