Freeman Freeman - 1 year ago 65
Perl Question

Parenthesis in regular expressions

Using Perl and:

my $s="The Sea! The Sea!"

The pattern
The Sea! The Sea!
because its matches the backreference

However, the pattern
does not match
The Sea! The Sea!


Answer Source

should work because inner captured group has become #2 now as outermost group is captured group #1.

Note that you can also use relative numbering of groups i.e.


Where \g{-1} will match most recent captured group.