Q:

regexp to remove entire paragraph based on it's content?

hey guys,
I'm a regexp noob,
Is it possible with preg_replace to remove a the an entire paragraph tag?
<p><div class="vidwrapper"> lot of content with oder divs etc. </div><p>

The paragraph should only be removed if it is following div has a class of .vidwrapper.
Is that even possible? Any idea how this regexp would look like?
Thank you for your help.

A:

If it's a fixed occurrence, then following might work:
preg_replace('#<p>[^<]*<div[^>]+class="vidwrapper"[^>]*>.*?</p>#is', "")

For matching nested html you would normally need a recursing regex, hencewhy something like phpQuery or QueryPath is then often simpler:
$html = pq($html)->find("p div.vidwrapper")->parent()->remove()->html();

