Auteur: ph10 Date: À: ND CC: Pcre-dev Sujet: Re: [pcre-dev] No capture in nested negative assertions
On Sun, 8 Jul 2018, ND via Pcre-dev wrote:
> May I suggest alternative approach? It is simple and more consistent. I think
> Perl use it:
>
> Capture is discarded ONLY if it was happen in non-matching branch.
Actually, this is *exactly* what should already happen! I was going to
post an explanation, but you beat me to it. Consider this:
Whenever any branch fails to match, there is a backtrack, and captures
within the branch are discarded. A negative assertion succeeds only if
all its branches fail. Therefore, after a successful negative assertion,
all captures are reset.
If any branch in a negative assertion succeeds, the captures are
(temporarily) kept, but as the whole assertion now fails, there is an
external backtrack, which discards the captures.
The only exception to this is when the assertion is a condition. In that
case, a successful branch causes the condition to be false, but matching
continues. The documentation says
When an assertion that is a condition contains capturing subpatterns,
any capturing that occurs in a matching branch is retained afterwards,
for both positive and negative assertions, because matching always
continues after the assertion, whether it succeeds or fails. (Compare
non-conditional assertions, when captures are retained only for
positive assertions that succeed.)
I will try to make the earlier part of the documentation (discussion
assertions) more clear about this.