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

Top Page
Delete this message
Author: ph10
Date:  
To: ND
CC: Pcre-dev
Subject: Re: [pcre-dev] Anchored patterns doesn't match with \K in lookbehind
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 at
the start of the subject string". By default, this is also the point
that is returned as the start of the match. However, \K can be used to
change *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