> How do I get a count of the number of matches a regex finds within a
string?
> 
> example:
> 
> $_ = "ABabcde12345BAABabcde1234blahblah5BA";
> print $1 if /(AB.*?BA)/ ;
> 
> Ultimate goal is to separate with \n.
> 
> Terry

Try this:

$string = "ABabcde12345BAABabcde1234blahblah5BA";
$count = $string =~ s/(?<=AB)(.*?)(?=BA)/$&/g ;
print "Count = $count\n";

I believe you can also use tr to count matches...

-Erich-

_______________________________________________
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to