CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Regular Expressions:
number of regex match

 



perl0user
Novice

Jan 15, 2009, 12:26 PM

Post #1 of 2 (1795 views)
number of regex match Can't Post

hi,
i'd like to know how to get the number of regexp matches a pattern returns
ex: if I have $_ = "fooFOObarBAR";$_ =~ /[a-z]/
it would return 6

thx

Smile

cvv3@yahoo.com


shawnhcorey
Enthusiast


Jan 15, 2009, 2:27 PM

Post #2 of 2 (1792 views)
Re: [perl0user] number of regex match [In reply to] Can't Post


Code
#!/usr/bin/perl 

use strict;
use warnings;

$_ = "fooFOObarBAR";
my $count = 0;
$count ++ while $_ =~ /[a-z]/g;
print "$count\n";


__END__

I love Perl; it's the only language where you can bless your thingy.

Perl documentation is available at perldoc.perl.org. The list of standard modules and pragmatics is available in perlmodlib.

Get Markup Help. Please note the markup tag of "code".

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives