正则表达式难题

WBOY
Release: 2016-06-23 14:02:12
Original
1081 people have browsed it

<?php$a="a11ba12b";preg_match_all("/(a[^b]+b){2}/is",$a,$tmp);var_dump($tmp);?>
Copy after login


得出的结果是

array(2) {  [0]=>  array(1) {    [0]=>    string(8) "a11ba12b"  }  [1]=>  array(1) {    [0]=>    string(4) "a12b"  }}
Copy after login



现在要问的是,如何操作使得使用{}中括号表示法,但是[1]中是= a11b,而不是 [1]=a12b,


回复讨论(解决方案)

\G?

    $a="a11ba11b";    preg_match_all("/\G(a[^b]+b){2}/i",$a,$tmp);    var_dump($tmp);
Copy after login

..baoqian
貌似错的

不如指定贪婪模式
preg_match_all("/(a[^b]+b)+/iU",$a,$tmp);

坐等大牛回答。

我就是在研究大括号,哈哈

这样? 你到底要干啥子吗

<?php$a="a11ba12b";preg_match_all("/(a[^b]+b)a[^b]+b/is",$a,$tmp);var_dump($tmp);
Copy after login

我就是在研究大括号,哈哈
这有什么可研究的?规矩就是规矩
{ 最少/最多数量限定开始 
} 最少/最多数量限定结束 

虽然规则有时不尽合理,但并不会因你而改变

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