Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

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]
[Eily]: it doesn't work in French AFAIK
[Eily]: I like the first one though :)
[erix]: balloonist, surely :P (or maybe baloneyist)
[marto]: afternoon all
[Corion]: Hi marto ;)
[Corion]: Eily: Yeah - my French isn't even good to understand jokes, much less to make them :-D
[Corion]: marto: That post is a repost/duplicate of Excel sheet data write issue :-D
[Corion]: Whoops - Merging worksheets in .xls in one Excel sheet
[marto]: Corion, whoops, can the moderation me amended?

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (7)
As of 2017-09-21 14:34 GMT
Find Nodes?
    Voting Booth?
    During the recent solar eclipse, I:

    Results (248 votes). Check out past polls.