如何在php中获取所有正则表达式匹配?
显然,brew和bunny应该匹配,但$matches只包含brew如何在php中获取所有正则表达式匹配?,php,regex,Php,Regex,显然,brew和bunny应该匹配,但$matches只包含brew 我应该怎么做才能让$matches包含所有正则表达式匹配项呢?您不需要正则表达式中+之后的b $pattern = '/b+[^\s-]*/'; $subject = 'brew and this is bunny'; preg_match($pattern, $subject, $matches); 输出 $str = 'brew and this is bunny'; preg_match_all('/b[^\s]+/'
我应该怎么做才能让$matches包含所有正则表达式匹配项呢?您不需要正则表达式中
+
之后的b
$pattern = '/b+[^\s-]*/';
$subject = 'brew and this is bunny';
preg_match($pattern, $subject, $matches);
输出
$str = 'brew and this is bunny';
preg_match_all('/b[^\s]+/', $str, $matches);
print_r($matches);
Array
(
[0] => Array
(
[0] => brew
[1] => bunny
)
)