我有一个字符串,完全如图所示,我试图匹配分隔符之间的内容。
# a
This is what should be matched/returned
# \a
# a
和# \a
是分隔符。
PHP /正则表达式不匹配:
$str = <<<EOD
# a
this is what should be returned
# \a
EOD;
preg_match("/#\sa\n(.*)\n#\s\\a/m", $str, $matches);
/*
Array
(
)
*/
print_r($matches);
我究竟做错了什么?
有几种方法可以做到:
s
的.
修饰符以匹配换行符\\\\
逃脱\
\r\n
而不仅仅是\n
所以我用\s
preg_match("/#\sa\s(.*)\s#\s\\\\a/s", $str, $matches);
为什么你在世界各地使用{1}
?