Here are some more solutions:
$count++ while ($str=~ /$pattern/g); # simple
or
$count= (scalar split /$pattern/, $str ) + ($str=~/$pattern$/) # or it will not be counted - 1; # so it's simpler
In reply to Re: Getting the number of times a regexp matches
by mirod
in thread Getting the number of times a regexp matches
by MeowChow
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |