Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: matching any string except a regex

by Fletch (Bishop)
on Mar 04, 2010 at 14:07 UTC ( [id://826707]=note: print w/replies, xml ) Need Help??


in reply to matching any string except a regex

This is probably on the borderline of what should be attempted with just regexen. The approach I'd take would be:

  • Use HTML::TreeBuilder to handle parsing the HTML
  • look_down the tree for p elements
  • Get the text contents of each of those elements and tokenize it on whitespace (i.e. using split)
  • Walk over the list of tokens, ignoring simple text, remembering the last mentioned book for wikirefs, and replacing textual references with the corresponding wikirefs
  • join the resulting items back together and replace the element contents

When the regex going gets tough, the tough get writing simple parsers and it's not so tough any more.

The cake is a lie.
The cake is a lie.
The cake is a lie.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (3)
As of 2024-04-26 05:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found