gpt4 book ai didi

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

转载 作者:可可西里 更新时间:2023-11-01 00:25:39 25 4
gpt4 key购买 nike

下面的代码无法检测到该事件的单个实例。 =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

关于php - 用于检测以星号开头的行的正则表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7590315/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com