[英]Regex to match and replace BB code quote
I am looking to match a string like this: 我正在寻找匹配这样的字符串:
[quote12445555=Me]Some \n Quote[/quote12445555]
And replace it with this: 并替换为:
<blockquote>Some \n Quote</blockquote>
I had regex for this as follows: 我为此正则表达式如下:
!\[quote(\d+)=(\w+)\](.*|\r\n|\n)\[\/quote(\d+)\]!
Replaced by: 取而代之:
<blockquote>$3</blockquote>
But it doesn't seem to be working 但这似乎不起作用
Any help or suggestions would be greatly appreciated. 任何帮助或建议,将不胜感激。
$quotes = preg_replace('%\[(quote\d+)=([^\]]+)\]([^[]+)\[/\1\]%', '<blockquote>$3</blockquote>', $quotes);
This appears to work in my tests: 这似乎在我的测试中起作用:
\[quote[0-9]+=[a-zA-Z0-9]+\]((.|\n)*)\[/quote[0-9]+\]
try changing: (.*|\\r\\n|\\n)
to (.|\\r\\n|\\n)*
尝试将
(.*|\\r\\n|\\n)
更改为(.|\\r\\n|\\n)*
does the forward slash need to be escaped? 是否需要转义正斜线?
\\/
My replace string was: <blockquote>$1</blockquote>
我的替换字符串是:
<blockquote>$1</blockquote>
仅供参考,正确的正则表达式为:
'!\[quote(\d+)\=(\w+)\](.+?)\[\/quote(\d+)\]!is'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.