Re: [pcre-dev] Anchored patterns doesn't match with \K in lo…

Top Page
Delete this message
Author: ND
Date:  
To: Pcre-dev
Subject: Re: [pcre-dev] Anchored patterns doesn't match with \K in lookbehind
May be a first sentence about \K in PCRE2 docs:

"The escape sequence \K causes any previously matched characters not to be
included in the final matched sequence"

need to add some remark about \K may also cause include in final matched
sequence characters that not exist in it and precede it

for example:
    (?<=\Kfoo)bar
matches
    bar
but report that match
    foobar




On 2018-06-25 08:21, ph10 wrote:
> On Mon, 25 Jun 2018, ND via Pcre-dev wrote:
>> PCRE2 version 10.31 2018-02-12
> > /(?<=\K.)/anchored
> > ab
> > No match
> >> As documented, "the pattern is forced to be "anchored", that is, it is
> > constrained to match only at the first matching point in the string
> that is
> > being searched".
> >> Match "a" at first matching point expected. But output is "no match".
>Oh dear. The invention of \K has confused a lot of things. I will try to
> reword the documentation."anchored" means "the current point at the
> start of the match must be atthe start of the subject string". By
> default, this is also the pointthat is returned as the start of the
> match. However, \K can be used tochange *what is reported* as the start
> of the matching string.
>Your pattern can never match, because when the starting point for the
> match is at the start of the string (i.e. when "anchored" is true) the
> backwards assertion must always fail, because there are no preceding
> characters.
>Philip
>--Philip Hazel
>