简体   繁体   中英

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 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);

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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