1 2 34
Associated with the matching variables C<$1>, C<$2>, ... are
-the B<backreferences> C<\1>, C<\2>, ... Backreferences are
+the B<backreferences> C<\g1>, C<\g2>, ... Backreferences are
matching variables that can be used I<inside> a regex:
- /(\w\w\w)\s\1/; # find sequences like 'the the' in string
+ /(\w\w\w)\s\g1/; # find sequences like 'the the' in string
-C<$1>, C<$2>, ... should only be used outside of a regex, and C<\1>,
-C<\2>, ... only inside a regex.
+C<$1>, C<$2>, ... should only be used outside of a regex, and C<\g1>,
+C<\g2>, ... only inside a regex.
=head2 Matching repetitions
/[a-z]+\s+\d*/; # match a lowercase word, at least some space, and
# any number of digits
- /(\w+)\s+\1/; # match doubled words of arbitrary length
+ /(\w+)\s+\g1/; # match doubled words of arbitrary length
$year =~ /\d{2,4}/; # make sure year is at least 2 but not more
# than 4 digits
$year =~ /\d{4}|\d{2}/; # better match; throw out 3 digit dates