簡體   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