in reply to counting overlapping patterns
Essentially, match successfully, count it, but then fail the match (an empty string can always match, so negating that always fails).sub match_count { my ($string, $pattern) = @_; my $n = 0; $string =~ /$pattern(?{ $n++ })(?!)/; return $n; }
-- Randal L. Schwartz, Perl hacker
Be sure to read my standard disclaimer if this is a reply.
|
---|