```{index} single: regnames_count; re function ``` ```{index} single: re::regnames_count; Perl function ``` # regnames_count Return the number of distinct named capture groups in the pattern of the most recent successful match. The count is always the number of *distinct* names defined in the pattern — it does not depend on which names participated in the match, and it does not necessarily match the length of what `regnames()` returns when that is called without its `$all` argument. ## Synopsis ```perl use re 'regnames_count'; "abc" =~ /(?x)|(?b)/; my $n = regnames_count(); # 2 ``` ## What you get back An integer count, or `undef` if there was no prior successful match in the current scope. ## Examples ```perl "foobar" =~ /(?\w+)/; print regnames_count(); # 1 "abc" =~ /(?.)(?.)(?.)/; # duplicate name 'a' print regnames_count(); # 2 — counts distinct names ``` ## Edge cases - No prior successful match — returns `undef`. - Pattern has no named captures — returns `0`.