```{index} single: regname (re) ``` ```{index} single: re::regname ``` # regname Returns the contents of a named capture group of the last successful match. ## Synopsis ```perl use re qw(regname); if ("2026-10" =~ /(?\d{4})-(?\d\d)/) { my $year = regname("y"); # '2026' } "a1" =~ /(?a)(?\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.