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

Re: [perl #124256] Regex loop for \K in lookbehind

Thread Next
April 28, 2015 11:14
Re: [perl #124256] Regex loop for \K in lookbehind
Message ID:
On Mon, 27 Apr 2015, James E Keenan via RT wrote:

> > I think this is a similar bug to the one I have just
> > fixed in PCRE.
> > 
> Can you provide a link to that fix?
> Thank you very much.

Not very easily (I'd have to check the SVN manual to figure out how to 
search for stuff - I'm a very simple user) and in any case the fix was 
different for PCRE1 and PCRE2. The bug was in the test programs pcretest 
and pcre2test rather than in the library itself (which only does single 
matches). Here is a comment from pcre2test.c:

    However, even after matching a non-empty string, there is still one     
    tricky case. If a pattern contains \K within a lookbehind assertion at the
    start, the end of the matched string can be at the offset where the match
    started. In the case of a normal /g iteration without special action, this
    leads to a loop that keeps on returning the same substring.

The code now checks for this case and advances the /g loop by one
character, just as it does for matching an empty string.


Philip Hazel

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