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

问一个正则,该如何解决

WBOY
Release: 2016-06-13 13:48:10
Original
824 people have browsed it

问一个正则

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);

Copy after login


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

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


谢谢!

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