Sunday, 18 August 2013

How can I get all matches of a regex in a string?

How can I get all matches of a regex in a string?

How can I use curl to get the contents of any html tag? In the following
script to get e.g. h1 contents:
#!/usr/bin/perl
use strict;
use warnings;
my $page = `curl www.yahoo.com`;
print "Page: \n";
sleep(5);
#print "$page \n";
if ($page =~ m/<h1\s*>(.*)<\/h1\s*>/ig){
print "$1 \n";
}
I get just one match. How can I get all matches?

No comments:

Post a Comment