Author: ND Date: To: Pcre-dev Subject: Re: [pcre-dev] Incompatibility with different names for subpatterns
of the same number
On 2018-07-22 15:09, ph10 wrote: >Consider /(?| (?<A>foo) | (?<B>bar) )/x
>The table will tell you "group 1 is called A" and "group 1 is called B".
> What happens if you match the pattern with "foo" and then ask "what is
> the value of group B?". The table will tell you that group B is group 1,
> and group 1 has matched "foo". But this is not right.
>
No. This is right as we purposefully use "(?|". When we write "(?|" we say:
I don't want a normal capture alias numbering. I want to <A> и <B> have
exactly one number.
If we want to differntiate <A> and <B> then we will don't use "(?|".
This is analogous to
/(?|(foo)|(bar))/
where we say:
I don't want a normal capture numbering. I want to <1> и <2> have exactly
one number.
And there are no surprises with this. As long as PCRE don't consider as
surprise
/(?|(foo)|(bar))(?1)/
when it don't match against "barbar"