in reply to Regexp to ignore HTML tags
UPDATE:use strict; use warnings; use HTML::Parser; my $parser = HTML::Parser->new(api_version => 3); $parser->handler(start => \&start, 'self,tagname,attr'); $parser->handler(text => \&text, 'self,dtext'); $parser->handler(end => \&end, 'self,tagname'); $parser->parse(q|<foo bar="qux" baz="foo">foo</foo>|); sub start { my ($parser,$tag,$attr) = @_; print "<$tag"; # we lose the original order of attribs, but we'll live ;) print qq| $_="$attr->{$_}"| for keys %$attr; print ">"; } sub text { my ($parser,$text,$attr) = @_; $text =~ s/foo/bar/g; print "$text"; } sub end { my ($parser,$tag) = @_; print "</$tag>"; }
jeffa
L-LL-L--L-LL-L--L-LL-L-- -R--R-RR-R--R-RR-R--R-RR B--B--B--B--B--B--B--B-- H---H---H---H---H---H--- (the triplet paradiddle with high-hat)
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: (jeffa) Re: Regexp to ignore HTML tags
by hiseldl (Priest) on Mar 31, 2003 at 16:47 UTC |