正则表达式替换Wordpress短代码

时间:2013-06-19 23:15:19

标签: regex wordpress replace

我有一个带有大量帖子的wordpress网站,其中包含以下类型的标记:

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

我想要一个正则表达式搜索/替换模式,它将搜索任何字符串,如

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

...并用空字符串替换它。

所以左边界定是

<div class="comments container">[song_comments

...正确的分隔符是

</div>

随着变量之间的一切。

关于如何做到这一点的任何想法?

1 个答案:

答案 0 :(得分:3)

使用此:

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

如果您对以下内容感兴趣:

preg_replace

www.regular-expressions.info

相关问题