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

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

Thread Next
From:
ph10
Date:
April 28, 2015 11:14
Subject:
Re: [perl #124256] Regex loop for \K in lookbehind
Message ID:
alpine.LNX.2.03.1504281210010.888@hermes.cam.ac.uk
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.

Regards,
Philip

-- 
Philip Hazel

Thread Next


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