Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Matching set of paragraph tags with string inside.

by Tanktalus (Canon)
on Feb 08, 2008 at 21:10 UTC ( [id://667069]=note: print w/replies, xml ) Need Help??


in reply to Matching set of paragraph tags with string inside.

If your HTML is actually XHTML-compliant, you could use XML::Twig to parse it, and then do something like this:

my @tagged_paragraphs = $twig->get_xpath('//p[string()=~/\[tag\]/'); my @texts = map { $_->text() } @tagged_paragraphs;
Note that if you have p's in p's (e.g., "<p>some text<p>inner [tag] stuff</p>outter</p>", this may give you problems (you'll get both "some textinner [tag] stuffoutter" and "inner [tag] stuff", I believe).

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (6)
As of 2024-04-24 06:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found