Re: [pcre-dev] Memory overflow when using replace modifier u…

Page principale
Supprimer ce message
Auteur: ph10
Date:  
À: ND
CC: Pcre-dev
Sujet: Re: [pcre-dev] Memory overflow when using replace modifier upon pattern with \K in lookbehind assertion
On Sat, 23 Jun 2018, ND via Pcre-dev wrote:

> The fact of error confusing me because there is no error happens without
> "replace":
>
>
> PCRE2 version 10.31 2018-02-12
> /(?<=\K.)/g
> ab
> 0: a
> 0: b


pcre2_substitute(), which is what "replace" calls, processes the string
from left to right. It finds a match, copies the preceding text to the
output, then copies the replacement, then starts the next search at tne
end point of the previous match. By using \K in a lookbehind assertion
at the start of your pattern, you have moved the start of the next match
to the left of the end of the previous match. This case is not supported
by pcre2_substitute().

Perl gets this wrong too. I tried your example and it sent Perl into a
loop and I had to power-cycle my maching in order to recover.

Philip

--
Philip Hazel