Home  >  Article  >  Backend Development  >  问一个正则,该如何解决

问一个正则,该如何解决

WBOY
WBOYOriginal
2016-06-13 10:09:08799browse

问一个正则

PHP code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->//匹配一个简单的URL$reg = '/(http:\/\/)?(.*\.)*[(com)|(cn)|(net)]/';$str = 'www.baidu.com/1/2/3/4/5/6';preg_match($reg, $str, $match);var_dump($match);


问题:
为什么打印$match结果是:
array(3) { [0]=> string(11) "www.baidu.c" [1]=> string(0) "" [2]=> string(10) "www.baidu." } 

只匹配到了www.baidu.c ???


谢谢!

------解决方案--------------------
探讨
[]的意思不就是取中括号中任意一个原子吗?如果不加+号,不就说明要她们中的一个必须且只能出现一次吗?
Statement:
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