http://www.perlmonks.org?node_id=565167


in reply to how to use regular expressions read some string from a htm file

You can use HTML::Parser:
#! /usr/bin/perl use strict; use warnings; use HTML::Parser; my @links; my $string = qq~<a href="url1">linktext1</a> Ein anderer Text <a href="url2">linktext2</a> text~; my $p = HTML::Parser->new(); $p->handler(start => \&start_handler,"tagname,attr,self"); $p->parse($string); foreach my $link(@links){ print "Linktext: ",$link->[1],"\tURL: ",$link->[0],"\n"; } sub start_handler{ return if(shift ne 'a'); my ($class) = shift->{href}; my $self = shift; my $text; $self->handler(text => sub{$text = shift;},"dtext"); $self->handler(end => sub{push(@links,[$class,$text]) if(shift eq 'a +')},"tagname"); }
  • Comment on Re: how to use regular expressions read some string from a htm file
  • Download Code