Note. Do not use regular expressions for HTML parsing.
This first option is done using HTML :: TreeBuilder , one of the many HTML available in Parsers. You can go to the link above and read the documentation and see the example given.
use strict;
use warnings;
use HTML::TreeBuilder;
my $str
= "<ul>"
. "<li>hello</li>"
. "<li>there</li>"
. "<li>everyone</li>"
. "</ul>"
;
my $tr = HTML::TreeBuilder->new_from_content($str);
my @lists =
map { $_->content_list }
$tr->find_by_tag_name('li');
foreach my $val (@lists) {
print $val, "\n";
}
, ( ). - ..
my $str
= "<ul>"
. "<li>hello</li>"
. "<li>there</li>"
. "<li>everyone</li>"
. "</ul>"
;
my @matches;
while ($str =~/(?<=<li>)(.*?)(?=<\/li>)/g) {
push @matches, $1;
}
foreach my $m (@matches) {
print $m, "\n";
}
:
hello
there
everyone