in reply to How can I access the number of repititions in a regex?

How can I count the number of occurrences of a substring within a string?
$count = () = $string =~ /-\d+/g;

Replies are listed 'Best First'.
Re^2: How can I access the number of repititions in a regex?
by pat_mc (Pilgrim) on Mar 11, 2008 at 13:12 UTC
    Hi, Anonymous Monk -

    What exactly does your code do? It looks as if it was trying to match for a pattern "-number" in $string ... how would that be of any help?
    Please explain.

    Thanks and regards -

    Pat