Home > Backend Development > PHP Tutorial > 解释上这个 正则表达式

解释上这个 正则表达式

WBOY
Release: 2016-06-13 12:55:48
Original
849 people have browsed it

解释下这个 正则表达式

<br />
preg_match_all("/<\?(?:(\d)|=)?/", "<?10", $mat)) <br />
//这个结果是<br />
    [0] => Array<br />
        (<br />
            [0] => <?1<br />
            [1] => 1//为什么会有它<br />
        )<br />
<br />
preg_match_all("/<\?(?:\d|=)?/", "<?10", $mat)) <br />
//这个结果是<br />
    [0] => Array<br />
        (<br />
            [0] => <?1<br />
        )<br />
//第一个多了一个小括号<br />
Copy after login


------解决方案--------------------
你要看手册,手册的例子说得很明白的
[0]表示整个正则匹配到的
[1]表示第一对小括号匹配到的
[2]表示第二对小括号匹配到的
……

(?: )则表示不进行匹配,所以没有进入到结果数组
------解决方案--------------------
多一对括号就多一组咯,以括号分组的。
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