in reply to Re: Counting multiple matches of RegExp in single line
in thread Counting multiple matches of RegExp in single line
will just work fine.$count = () = $teststring =~ /test/g;
This is documented in perlop, see the last sentence in this paragraph:
The "/g" modifier specifies global pattern matching--that is, matching as many times as possible within the string. How it behaves depends on the context. In list context, it returns a list of the substrings matched by any capturing parentheses in the regular expression. If there are no parentheses, it returns a list of all the matched strings, as if there were parentheses around the whole pattern.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Counting multiple matches of RegExp in single line
by gaal (Parson) on Nov 27, 2004 at 13:28 UTC |