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

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

Thread Previous
From:
demerphq
Date:
April 4, 2007 02:26
Subject:
Re: [perl #42289] Second Zero-Length Iterative Regexp Match Fails
Message ID:
9b18b3110704040226o373c46bbq7b68819c202349c2@mail.gmail.com
On 4/3/07, via RT Andri <perlbug-followup@perl.org> wrote:
> # New Ticket Created by  Andri
> # Please include the string:  [perl #42289]
> # in the subject line of all future correspondence about this issue.
> # <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=42289 >
>
>
> 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.

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

Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About