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

Re: matching any string except a regex

by Fletch (Bishop)
on Mar 04, 2010 at 14:07 UTC ( #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?

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (2)
As of 2023-06-06 01:50 GMT
Find Nodes?
    Voting Booth?
    How often do you go to conferences?

    Results (26 votes). Check out past polls.