Skip to content Skip to sidebar Skip to footer

How, Using Regex, Can I Capture The Outer Html Element, When The Same Element Type Is Nested Within It?

I'm trying to capture certain parts of HTML using regular expressions, and I've come across a situation which I don't know how to resolve. I've got an HTML fragment like this: <

Solution 1:

Obviously, the "right" answer is to use a DOM parser instead of regex, but you say your markup is too broken for a parser.

Before resorting to a regex, though, check out whether simpleHTMLDOM can make sense out of it. it is a bit more lenient towards broken markup than the PHP DOM based parsers.

Post a Comment for "How, Using Regex, Can I Capture The Outer Html Element, When The Same Element Type Is Nested Within It?"