in reply to Regular expression problem
This is a case of "don't use regexes to parse HTML" :)
#!perl -w use strict; use HTML::Parser; my $html = <<'END_HTML'; <html> <body> <form action="/foo.pl" method="post"> Username: <input type="text" name="user" onClick="alert('You clicked me!')" /><br /> Password: <input type="password" name="passwd" onChange="alert('You changed me!')" /> </form> </body> </html> END_HTML my $parser = HTML::Parser->new( start_h => [ \&_parser_starttag, 'tagname, attr' ] ); $parser->parse( $html ); sub _parser_starttag { my ($tag, $attr) = @_; if ( exists $attr->{'onchange'} ) { warn( "<$tag> - onChange: ", $attr->{'onchange'}, "\n" ); } elsif ( exists $attr->{'onclick'} ) { warn( "<$tag> - onClick: ", $attr->{'onclick'}, "\n" ); } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Regular expression problem
by jockel (Beadle) on Jun 09, 2004 at 09:05 UTC | |
by saskaqueer (Friar) on Jun 09, 2004 at 09:52 UTC | |
by jeffa (Bishop) on Jun 09, 2004 at 15:31 UTC |