$pattern = '/b+[^\s-]*/';
$subject = 'brew and this is bunny';
preg_match($pattern, $subject, $matches);
显然,brew和bunny应匹配,但$ match只包含brew。
如果$ match包含所有正则表达式匹配
,我该怎么做答案 0 :(得分:1)
您的正则表达式中+
之后不需要b
。
$str = 'brew and this is bunny';
preg_match_all('/b[^\s]+/', $str, $matches);
print_r($matches);
输出
Array
(
[0] => Array
(
[0] => brew
[1] => bunny
)
)