Home > Backend Development > PHP Tutorial > 容易的正则求大家指点

容易的正则求大家指点

WBOY
Release: 2016-06-13 11:17:43
Original
806 people have browsed it

简单的正则求大家指点
$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

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template