Home  >  Article  >  Backend Development  >  怎么理解这个正则表达式呢?

怎么理解这个正则表达式呢?

WBOY
WBOYOriginal
2016-06-06 20:52:421110browse

preg_match('/[^a-z0-9\\/\\\\_.:-]/i', $filename);

回复内容:

preg_match('/[^a-z0-9\\/\\\\_.:-]/i', $filename);

作为正则爱好者,先表达一下看到正则问题的兴奋~~~
其实这个表达式不复杂。。。

$result = preg_match('/[^a-z0-9\\/\\\\_.:-]/i', $filename);

如果,$filename 含有非 “a到z”, “A到Z”, “0到9”, “/”, “\”, “_”, “.” , “:”, “-” 以外的任意一个字符,返回真
否则,返回假

[^]表示除去括号内字符的字符,[^a-z0-9\\/\\\\_.:-]表示除去[]内的字符,也就是除去a~z,0~9,\ /_-.:

例如:

字符串 -> aB09CA\\/asDf_asdfA.Dcva:df-D
利用[^a-z0-9\\/\\\\_.:-]后 -> BCADADD
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