Home  >  Article  >  Backend Development  >  简单的正则求大家指点

简单的正则求大家指点

WBOY
WBOYOriginal
2016-06-23 14:03:17811browse

$str='cbaaaa';
$preg='/ba*/';
preg_match($preg,$str,$arr);
dump($arr[0]);
这个结果是baaaa能理解

$str='bbaaaa';
$preg='/ba*/';
preg_match($preg,$str,$arr);
dump($arr[0]);
这个结果为什么会是b呢?



回复讨论(解决方案)

$preg='/ba*/';
等同
$preg='/ba{0,}/';

然后你用
preg_match_all($preg,$str,$arr);

打印下$arr 就知道咋回事了

楼上正解

你的第二个正则表达式遇到第一个b就已经匹配了。所以不会匹配之后的baaaa

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn