Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: How to parse not closed HTML tags that don't have any attributes?

by tybalt89 (Monsignor)
on Mar 06, 2021 at 23:24 UTC ( [id://11129230]=note: print w/replies, xml ) Need Help??


in reply to How to parse not closed HTML tags that don't have any attributes?

#!/usr/bin/perl use strict; use warnings; local $_ = do { local $/; <DATA> }; while( /<p class="title">(\w+)<\/p>\s*<p>([^<>]*)/g ) { my $title = $1; printf "%20s %s", $title, $2 =~ s/\s*\z/\n/r; } __DATA__ <div class="phone"> <div class="icon"></div> <p class="title">Telephone</p> <p>0123-4 56 78 90 <p class="title">Telefax</p> <p> </div>

Outputs:

Telephone 0123-4 56 78 90 Telefax

Well, it works for all the provided test cases :)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11129230]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (8)
As of 2024-04-23 12:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found