How to match a table tag in Perl regex? -
How to match a table tag in Perl regex? -
i tried
/(^<table)(.*?)($>)/
it should match between <>
table tag, not
as mentioned in comments on this question, it's not practical parse html regular expressions.
here's illustration using mojo::dom, inspired this stackoverflow answer:
#!/usr/bin/env perl utilize strict ; utilize warnings ; utilize mojo::dom ; $html = <<eohtml; <!doctype html> <html> <head> <title>sample html table</title> </head> <body> <table border> <tr> <td>a</td> <td>b</td> <td>c</td> </tr> <tr> <td>1</td> <td>2</td> <td>3</td> </tr> </table> </body> </html> eohtml $dom = mojo::dom->new ; $dom->parse( $html ) ; $div ( $dom->find( 'td' )->each ) { print $div->all_text . "\n" ; }
the output is:
a b c 1 2 3
regex perl
Comments
Post a Comment