Very nice. :)
You can go a step better by making the outer match minimal, which means it will immediately match zero times and thus avoid the time and danger of trying to match the interior at all:
@capture_count = /($regex)??/; print @capture_count - 1, " captures\n";
Hugo
In reply to Re: Re: Trying to count the captures in a compiled regular expression
by hv
in thread Trying to count the captures in a compiled regular expression
by BooK
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |