试图调整正则表达式以删除新行


trying to adjust regex to remove new lines

你好,我想调整这个正则表达式:

/'[quote'](.+?)'['/quote']'r'n/is

基本上忽略新行(基本上我希望我的引号系统删除引号bbcode之后的任何新行,以停止引号后的双空格。

目前我只是这样做作为替换:

$replace = "<div class='"quote'"><span class='"strong'">Quote</span><br />$1</div>";

所以它直接删除了新行,但是如果引号代码是页面上的最后一个内容并且后面没有新行,它就会中断

想到了一个简单的方法:

$body = str_replace("[/quote]'r'n", '[/quote]', $body);

在文本中勾选之前删除它们。简单的解决方案,没有麻烦。

在末尾添加一个非捕获组,如下所示:

/'[quote'](.+?)'['/quote'](?:'r'n)*/is

或者一个简单的字符类:

/'[quote'](.+?)'['/quote']['r'n]*/is

这将捕获单个'n break