开发者

Regular expression to detect line that starts with an asterisk

开发者 https://www.devze.com 2023-04-08 22:27 出处:网络
The code below fails to detect a single instance of the occurance. =O Whats wrong? =\\ How do I detect the following lines (which begin with a newline) that begin with an asterisk ? I\'m at a loss. T

The code below fails to detect a single instance of the occurance. =O Whats wrong? =\

How do I detect the following lines (which begin with a newline) that begin with an asterisk ? I'm at a loss. This isn't behaving as I expected.

$text ="Nothing here to detect...though it is the first line.
* '' [[test]]
* Another lin开发者_JAVA百科e 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);


add the m modifier to specify that this has a multi line subject like #^\*.*#m

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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号