Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
$pattern = '/b+[^\s-]*/'; $subject = 'brew and this is bunny'; preg_match($pattern, $subject, $matches);
显然,brew 和 bunny 应该匹配,但 $matches 只包含 brew。
我应该怎么做才能让 $matches 包含所有正则表达式匹配
你不需要+在b你的正则表达式之后。
+
b
$str = 'brew and this is bunny'; preg_match_all('/b[^\s]+/', $str, $matches); print_r($matches);
输出
Array ( [0] => Array ( [0] => brew [1] => bunny ) )