regname#
Returns the contents of a named capture group of the last successful match.
Synopsis#
use re qw(regname);
if ("2026-10" =~ /(?<y>\d{4})-(?<m>\d\d)/) {
my $year = regname("y"); # '2026'
}
"a1" =~ /(?<d>a)(?<d>\d)?/;
my $all = regname("d", 1); # ['a', '1']
A name can label more than one group. Without the second argument, or with it false, the result is the first of those groups that matched. With it true, the result is an array reference holding one entry per group of that name, in pattern order, with undef for a group that did not take part in the match.