Re: [pcre-dev] \K in lookahead assertion gives unpredictable…

Top Page
Delete this message
Author: ph10
Date:  
To: ND
CC: pcre-dev
Subject: Re: [pcre-dev] \K in lookahead assertion gives unpredictable result
On Fri, 27 Dec 2013, ND wrote:

> > /(?=ab\K)/+
> >    abcd
> > Start of matched string is beyond its end - displaying from end to start.
> > 0: ab
> > 0+ abcd

> >
>
> Sorry. But I don't understand why result is 'ab'. I think result must be ''.


The start of the match, as set by \K, is after "ab". The end of the
match, which is where the "current position" is, is before "ab". Those
two values are reported to pcretest, which has chosen to tell you that
the start is after the end, and then display from the end to the start
so you can see where the start and end are. A different application can
chose to make a different interpretation of the values that the PCRE
library returns (which in this case are 2 for the start ad 0 for the
end). If pcretest just printed "", the effect of \K would not be
indicated.

Philip

--
Philip Hazel