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.

תקציר#

use re 'regnames_count';
"abc" =~ /(?<a>x)|(?<b>b)/;
my $n = regnames_count();     # 2

מה מוחזר#

An integer count, or undef if there was no prior successful match in the current scope.

דוגמאות#

"foobar" =~ /(?<w>\w+)/;
print regnames_count();         # 1

"abc" =~ /(?<a>.)(?<b>.)(?<a>.)/;   # duplicate name 'a'
print regnames_count();         # 2 - counts distinct names

מקרי קצה#

  • No prior successful match - returns undef.

  • Pattern has no named captures - returns 0.