繁体   English   中英

正则表达式,用于检测以星号开头的行

[英]Regular expression to detect line that starts with an asterisk

下面的代码无法检测出现的单个实例。 = O什么错了? = \\

如何检测以星号开头的以下行(以换行符开头)? 我不知所措。 这不符合我的预期。

$text ="Nothing here to detect...though it is the first line.
* '' [[test]]
* Another line that starts with an asterisk 
** yet another...though it has two...but who cares about the 2nd one?";


$t = preg_match_all('#^\*.*#', $text, $match);
echo "found=".$t."\n";
print_r($match);

添加m修饰符以指定它具有多行主题,如#^\\*.*#m

http://php.net/manual/en/reference.pcre.pattern.modifiers.php

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM