Re: [pcre-dev] No capture in nested negative assertions

Kezdőlap
Üzenet törlése
Szerző: ph10
Dátum:  
Címzett: ND
CC: Pcre-dev
Tárgy: Re: [pcre-dev] No capture in nested negative assertions
On Tue, 10 Jul 2018, ND via Pcre-dev wrote:

> I guess Perl doesn't backtrack if last alternative of negative assertion
> fails.


Not quite (see below). I suspect it is just the way the Perl code turned
out rather than a deliberate design. I couldn't find any Perl
documentation about this.

> PCRE2 version 10.31 2018-02-12
> /(?!(a)b)/allcaptures
> a
> 0:
> 1: <unset>


Indeed, but the way Perl works means that adding another branch changes
things:

Perl 5.026002 Regular Expressions
/(?!(a)b)/
a
0:
1: a

/(?!(a)b|ac)/
a
0:

/(?!ac|(a)b)/
a
0:

It seems to save the capture only if there is just one branch in the
assertion. Or maybe it has some algorithm for deciding on which branch
to try first ... I don't know, but it all seems very inconsistent to me.

PCRE2 consistently discards the captures in all cases.

Philip

--
Philip Hazel