- Log -----------------------------------------------------------------
commit 408633379a1452b4e14d7c3b5e80f7dc05ea7986
Author: Moritz Lenz <mor...@faui2k3.org>
Date: Fri Nov 27 00:33:09 2009 +0100
Document backreferences to groups that did not match
Also add a test for that, fill in test description, and sneak in a vim
modeline for re_tests
-----------------------------------------------------------------------
Summary of changes:
pod/perlre.pod | 4 ++++
t/re/re_tests | 5 ++++-
2 files changed, 8 insertions(+), 1 deletions(-)
diff --git a/pod/perlre.pod b/pod/perlre.pod
index df627ff..42017dd 100644
--- a/pod/perlre.pod
+++ b/pod/perlre.pod
@@ -518,6 +518,10 @@ backreference only if at least 11 left parentheses have opened
before it. And so on. \1 through \9 are always interpreted as
backreferences.
+If the bracketing group did not match, the associated backreference won't
+match either. (This can happen if the bracketing group is optional, or
+in a different branch of an alternation.)
+
X<\g{1}> X<\g{-1}> X<\g{name}> X<relative backreference> X<named backreference>
In order to provide a safer and easier way to construct patterns using
backreferences, Perl provides the C<\g{N}> notation (starting with perl
diff --git a/t/re/re_tests b/t/re/re_tests
index 725a752..dc03084 100644
--- a/t/re/re_tests
+++ b/t/re/re_tests
@@ -275,7 +275,8 @@ a[-]?c ac y $& ac
\g{0} - c - Reference to invalid group 0
\g{-0} - c - Reference to invalid group 0
(a)|\1 a y - -
-(a)|\1 x n - -
+(a)|\1 x n - Reference to group in different branch
+(?:(b)?a)\1 a n - Reference to group that did not match
(a)|\2 - c - Reference to nonexistent group
(([a-c])b*?\2)* ababbbcbc y $&-$1-$2 ababb-bb-b
(([a-c])b*?\2){3} ababbbcbc y $&-$1-$2 ababbbcbc-cbc-c
@@ -1393,3 +1394,5 @@ foo(\h)bar foo\tbar y $1 \t
'[\x{100}\xff]'i \x{ff} y $& \x{ff}
((??{ "(?:|)" }))\s C\x20 y - -
+
+# vim: set noexpandtab
--
Perl5 Master Repository