删除两个引号标签之间的所有内容

Remove everything between two quote tags

文本中包含一些带有随机数字的引号。

参见:

$string = '[quote="Member123":hk1f9ynv]This is the quote Text  and we want remove it.[/quote:hk1f9ynv]

Here is the anwser to the quote. 

[quote:hk1f9ynv]Here is another quote, we want remove it too.[/quote:hk1f9ynv]

Thank you very much. Good job!';

数据库中存储的编号:hk1f9ynv 是随机的

输出应如下所示:

这里是引用的答案。非常感谢你。干得好!

我在堆栈上尝试了很多解决方案。似乎没有任何效果。示例:

preg_replace('/\[[^>]*\]/', '', $string); 
preg_replace('\[/?abc.*?\]', '', $string);

非常感谢。

你为什么不直接使用 $string.substr(0, $string.indexOf("]"))

preg_replace的两种可能方法:

第一个忽略引用标签的id:

~\[quote\b [^]]* ]
 [^[]*+
 (?: (?:\[ (?!/?quote\b) | (?R) ) [^[]* )*+
 \[/quote\b [^]]* ]~x

demo

第二个捕获 id 并使用它来查找结束标记:

~\[quote\b [^]:]* : (?<id>[^:]*) ]
 .*? # or: [^[]*+ (?:\[(?!\[/quote\b [^]:]* : \g{id} ])[^[]*)*+
 \[/quote\b [^]:]* : \g{id} ]~xs

demo

这两种模式旨在处理嵌套标签。