Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Re: SOLVED:Regular expression fetching multiple matches

by 7stud (Deacon)
on Jan 14, 2013 at 03:02 UTC ( #1013149=note: print w/replies, xml ) Need Help??

in reply to SOLVED:Regular expression fetching multiple matches

I forgot to mention something else:

5) Don't try to parse html with your own regexes. There are plenty of perl HTML parsers that do the hard work for you. Here is one example:

use strict; use warnings; use 5.012; use HTML::TreeBuilder; my $string = <<END_OF_HTML; <ul> <li> <div id="Show1400"> <a href="../../../KeyboardKeys/RetainerClip/Acer/Aspire/1400">14 +00</a> </div> </li> <li> <div id="Show1410"> <a href="../../../KeyboardKeys/RetainerClip/Acer/Aspire/1410">14 +10</a> </div> </li> END_OF_HTML #Note the missing </ul> tag above. my $tree = HTML::TreeBuilder->new(); $tree->parse_content($string); my @links = $tree->look_down('_tag', 'a'); for my $link (@links) { say $link->attr('href'); } --output:-- ../../../KeyboardKeys/RetainerClip/Acer/Aspire/1400 ../../../KeyboardKeys/RetainerClip/Acer/Aspire/1410

The docs on how to use HTML::TreeBuilder are at HTML::Tree::Scanning.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1013149]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (6)
As of 2017-11-24 15:52 GMT
Find Nodes?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:

    Results (350 votes). Check out past polls.