Home > Backend Development > PHP Tutorial > preg_match正则基础题,该如何处理

preg_match正则基础题,该如何处理

WBOY
Release: 2016-06-13 11:50:37
Original
785 people have browsed it

preg_match正则基础题

<?PHP<br />preg_match("/^(http:\/\/)?([^\/]+)/i","http://www.php.net/index.html",$arr);<br />print_r($arr);<br />?>
Copy after login


最后结果:http://www.php.net

^(http:\/\/)?可以匹配http://  可以理解

为什么([^\/]+)可以匹配 www.php.net 不解?

------解决方案--------------------
[^\/]+表示匹配多个不是‘/’的字符 当然就可以匹配到www.php.net了 因为该字符没有 / 字符
------解决方案--------------------
[^\/]+ 表示匹配除了字符”/“的所有字符,当然包括 www.php.net
------解决方案--------------------
理解好[^ \/]这个就可以了,表示除“/”这个以外的任何东西,[^ ]这个是特定的,"\"是转义符

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