Regular expression to detect line that starts with an asterisk
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
精彩评论