in reply to regex match word , don't match word preceeded by slash
#!/usr/bin/perl -- use strict; use warnings; use HTML::TreeBuilder; my $html = '<html><body> <a href="/cgi-programming-with-perl.zip">cgi-programming-with-perl.zip +</a> <a href="cgi-programming-with-perl.zip">cgi-programming-with-perl.zip< +/a> </body></html>'; { my $tree = HTML::TreeBuilder->new(); $tree->ignore_ignorable_whitespace(0); $tree->no_space_compacting(1); $tree->parse( $html )->eof; $tree->look_down( qw' _tag a href ', qr!^/! , sub { $_[0]->push_content( HTML::Element->new('b')->push_content( $_[0]->detach_content ), ); return; }, ); print $tree->as_HTML('<>&',' ',{}), "\n"; } __END__ <html> <head> </head> <body> <a href="/cgi-programming-with-perl.zip"><b>cgi-programming-with-perl. +zip</b></a> <a href="cgi-programming-with-perl.zip">cgi-programming-with-perl.zip< +/a> </body> </html>
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: regex match word , don't match word preceeded by slash
by lepetitalbert (Abbot) on Nov 19, 2010 at 03:19 UTC | |
by kcott (Archbishop) on Nov 19, 2010 at 03:54 UTC | |
by lepetitalbert (Abbot) on Nov 20, 2010 at 18:29 UTC |