http://www.perlmonks.org?node_id=653746


in reply to Regex to match first html tag previous to text

I'd use HTML::TreeBuilder::XPath to find the nodes in question, then alter the values in the "DOM" and use methods from HTML::Tree to write the document back out.

Regular expressions are a very fragile solution to the "how do I parse HTML" problem.

-David

  • Comment on Re: Regex to match first html tag previous to text

Replies are listed 'Best First'.
Re^2: Regex to match first html tag previous to text
by Greebo (Initiate) on Nov 30, 2007 at 17:09 UTC
    Thanks for the reply - as it happened (as it so often happens whenever I post asking for help with something) I stumbled upon a regex solution to this problem by accident, but given the majority of people saying regex is not the way to go here, I will definitely look into this and the various other options people suggested