More information about the Underscore mailing list

[_] php regex - remove nested lists in nav

Oliver Humpage oliver at
Fri Feb 1 10:46:20 GMT 2013

On 1 Feb 2013, at 10:38, juan kennaugh wrote:

> I'm no regex or php expert - so wondering if anyone could tell me if there's a simple way of removing a nested list from a nav markup string using regex?

/html+regex autoresponder alert:

Use a DOM parser :)

I mean, yes, you could use something like:

preg_replace("#(<li[^<]+)<ul.+?</ul>#", "$1", $nav_markup)

But that relies on your markup being simple and not having anything weird in it. So to prevent accidents, a DOM parser (or even just something like simplexml) is the way to go.