http://www.perlmonks.org?node_id=369911


in reply to Count capturing parentheses in a compiled regexp

In the spirit of "match the regex to get the number of parens in it", here's another way:
sub nparens { "" =~ /|$_[0]/ and $#+ }
_____________________________________________________
Jeff[japhy]Pinyan: Perl, regex, and perl hacker, who'd like a job (NYC-area)
s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;