RE: count of matches

2004-12-23 Thread Beckett Richard-qswi266
You can also use this bizarre construction to capture just the count: $_ = ABabcde12345BAABabcde1234blahblah5BA; $count = () = $_=~ /(AB.*?BA)/g; print I matched $count times\n' the () between the two ='s forces the match to list context, and then THAT is forced to scalar

RE: count of matches

2004-12-23 Thread Andy_Bach
Try: #!/usr/bin/perl -w use strict; $_ = ABabcde12345BAABabcde1234blahblah5BA; print is: , $_ , \n; my $count = () = $_=~ /(AB.*?BA)/g; my @match = /(AB.*?BA)/g; print match: , join(, , @match), \n; print I matched $count times\n; The trick is: $_ =~ /../ applies the

RE: count of matches

2004-12-22 Thread Anderson, Mark (Service Delivery)
=~ m//g returns the number of matches if evaluated in list context so... $_ = ABabcde12345BAABabcde1234blahblah5BA; print $1 if /(AB.*?BA)/ ; becomes $_ = ABabcde12345BAABabcde1234blahblah5BA; @count=$_=~/(AB.*?BA)/g; print I matched . scalar @count . times\n; If you

RE: count of matches

2004-12-22 Thread Erich Beyrent
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 =~

Re: count of matches

2004-12-22 Thread Kester Allen
You can also use this bizarre construction to capture just the count: $_ = ABabcde12345BAABabcde1234blahblah5BA; $count = () = $_=~ /(AB.*?BA)/g; print I matched $count times\n' the () between the two ='s forces the match to list context, and then THAT is forced to scalar context by