in reply to Getting the number of times a regexp matches
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Getting the number of times a regexp matches
by chipmunk (Parson) on Dec 07, 2000 at 19:07 UTC | |
|
Re: Re: Getting the number of times a regexp matches
by t0mas (Priest) on Dec 07, 2000 at 15:41 UTC | |
by mirod (Canon) on Dec 07, 2000 at 15:47 UTC |