I only get a one when doing it that way. I had to do the following:

my $string = 'abcadebavdacde';
my $MyCount = 0;
while ( $string =~ /a/g ) { $MyCount++};

printf "String:\n%-s\nCount: %4d\n", $string, $MyCount;

Output:

String:
abcadebavdacde
Count:    4

Wags ;)

-----Original Message-----
From: Carl Rogers [mailto:[EMAIL PROTECTED]]
Sent: Thursday, June 14, 2001 14:09
To: [EMAIL PROTECTED]; [EMAIL PROTECTED]
Subject: Re: counting regex matches



>
>$string =~ /a/g; # match on all 'a' in $string
>
>Now how do I know how many times it actually matched?

Try:
$result = $string =~ /a/g;
The value will be in $result

Carl

Reply via email to