我尝试使用preg_match_all
来匹配...
和...
之间的任何内容,并且该行会自动换行。我已经在谷歌上完成了大量搜索并尝试了不同的组合,但没有任何工作。我试过这个
preg_match_all('/...(.*).../m/', $rawdata, $m);
下面是格式的示例:
...this is a test...
...this is a test this is a test this is a test this is a test this is a test this is a test this is a test this is a test this is a test...
答案 0 :(得分:1)
s
修饰符允许.
包含换行符,请尝试:
preg_match_all('/\.{3}(.*?)\.{3}/s', $rawdata, $m);
您使用的m
修饰符是^$
基于每行而不是每个字符串(因为您没有^$
没有意义)。
您可以阅读有关修饰符here的更多信息。
请注意,.
也需要进行转义,因为它是一个特殊字符,意为any character
。 ?
之后的.*
使其非贪婪,因此它将匹配找到的第一个...
。 {3}
表示前一个字符中的三个。
Regex101演示:https://regex101.com/r/eO6iD1/1
答案 1 :(得分:0)
请逃避字面点,因为字符也是正则表达式的预留符号,因为您自己在代码中使用它:
preg_match_all('/\.\.\.(.*)\.\.\./m/', $rawdata, $m)
如果你想说的是内容中有换行符,那么你必须明确地将它添加到你的代码中:
preg_match_all('/\.\.\.([.\n\r]*)\.\.\./m/', $rawdata, $m)
点击此处查看点包含的字符的参考: http://www.regular-expressions.info/dot.html
答案 2 :(得分:0)
你快要接近了,
因此您需要更新stylesheet
RE
参与细分
/\.{3}(.*)\.{3}/m
:字符串的开头/结尾
/
:匹配\.
.
:完全匹配3(在这种情况下恰好匹配3个点)
{3}
:匹配第一场比赛((.*)
)
...
:匹配多行的字符串。
当你把所有东西放在一起时,你就会有这个
m
输出
$str = "...this is a test...";
preg_match_all('/\.{3}(.*)\.{3}/m', $str, $m);
print_r($m);
<强> DEMO 强>