--- Rule.pod.orig 2006-10-10 17:26:39.000000000 -0400 +++ Rule.pod 2006-10-10 17:37:17.000000000 -0400 @@ -1956,6 +1956,21 @@ C<(undef, undef, undef, undef, undef, undef, 'every', 'green', 'BEM', 'devours', 'faces')> (as the same regex would in Perl 5). +If non-capturing brackets are used, this can become more complex. +Every time C<|> appears inside of non-capturing brackets, the subpattern +index is returned to the index that it had when entering the +brackets. When exiting the brackets, the next capturing subpattern +will have an index one higher than the highest subpattern inside +the non-capturing brackets. Here is such an example: + + # $0 $1 $2 $1 $3 + $match = rx/ (a) [ (b) (c) | (d) ] (e) /; + +Notice that it is not the most recent C<$1> that determines +the index of the C<(e)> subpattern, but the C<(c)> subpattern that +incremented the index to C<$2>. Therefore C<(e)> has an index +of C<$3>. + =item * Note that it is still possible to mimic the monotonic Perl 5 capture
The example in S05 under "Subpattern numbering" isn't quite complex
enough to give the reader a full understanding of the ramifications of
the re-numbering that occurs with alternations, especially with respect
to the combination of capturing and non-capturing subpatterns. I've
written a small example and explanation to address this (attached as
diff) based on an IRC conversation with fglock. If it's deemed correct,
could this be included, please?