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

Αρχική Σελίδα
Delete this message
Συντάκτης: ph10
Ημερομηνία:  
Προς: ND
Υ/ο: Pcre-dev
Αντικείμενο: Re: [pcre-dev] No capture in nested negative assertions
On Fri, 6 Jul 2018, ND via Pcre-dev wrote:

> PCRE documents:
> "No capturing is done for a negative assertion unless it is being used as a
> condition in a conditional subpattern (see the discussion below). Matching
> continues after a non-conditional negative assertion only if all its branches
> fail to match."
>
>
> But capture also matters if it is inside even number of nested negative
> assertions. But PCRE ignore this and unset capture:


When I looked at this issue originally, I seem to remember that Perl was
inconsistent on what it did in different cases. But of course, Perl
keeps on changing... I can't find any Perl documentation about this.

However, when I was implementing this I could not see an easy way of
defining what capturing inside a negative assertion actually means
outside of the assertion itself. The documentation needs updating to
make it clear that *within* the assertion, capturing can be used.

This is even worse if (?| is used in such an assertion, because it may
"capture" the same group several times while it checks that all the
branches fail to match. I decided that the most straightforward approach
was to discard all capturing inside negative assertions when the
assertion completes.

> PCRE2 version 10.31 2018-02-12
> /(?!(?!(.)))/


PCRE2 is nowhere near clever enough to recognize that two negatives make
a positive.

Philip

--
Philip Hazel