简单的正则求大家指点

WBOY
Release: 2016-06-23 14:03:17
Original
809 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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!