Home  >  Article  >  Backend Development  >  这么理解正则对吗

这么理解正则对吗

WBOY
WBOYOriginal
2016-06-13 12:27:03982browse

这样理解正则对吗
看到别人写的正则是如下:
if (!preg_match('/^[\w\-\.]+@[\w\-\.]+(\.\w+)+$/',$_string))
其中对于中括号及里面的理解,我是这样的:中括号表示其中任意一项;
那么,上面这段中的它[\w\-\.]我就理解成了前面第一个打头的可以是所有任意英文字符,或是横杠,或是点都可以

如果上面的理解对,那么 问题来了,这段代码的作用是为了验证email的正确性。
大家知道email第一个打头的不能是横杠,这不就错了吗?

------解决思路----------------------
你的正则可以匹配 ...@....net
你说对吗?

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