0

I have a wordpress site with a ton of posts with the following kind of markup:

<div class="comments container">[song_comments song_slug="this time"]</div>

I want a regex search/replace pattern which will search for any string like

<div class="comments container">[song_comments XXXXXXXXXXXXXXXXXXX</div>

...and replace it with an empty string.

So the left delimiter is

<div class="comments container">[song_comments

...and the right delimiter is

</div>

With everything between being variable.

Any ideas on how to do this?

1
  • You want to remove the whole div or just [......... part ? Commented Jun 19, 2013 at 23:20

1 Answer 1

3

Use this:

$html = preg_replace(
    '~<div class=["\']comments container["\']>\[song_comments[^<]++</div>~',
    '', $html);

If you are interested by:

preg_replace

www.regular-expressions.info

Sign up to request clarification or add additional context in comments.

1 Comment

THANKS! One of those skills---like card tricks, I keep meaning to master in order to dazzle people like me. What usually gets me stumped are special characters like brackets and hairpins. Gotta study this. I only need it once in a great while, but when I need it... I NEED it. Big cheers!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.