【发布时间】:2013-11-30 14:01:17
【问题描述】:
这是我验证密码的模式:
$pattern = '/^[0-9A-Za-z!@#$^%*_|;:\'"`~.,\(\)\{\}\[\]\<\>\\\/\?\-\+\=\&]{6,}$/m';
我使用函数preg_match 来验证
preg_match($pattern, $string);
但是当我运行它时,它显示了这个错误:
Warning: preg_match(): Unknown modifier '\' in xxx on line 13
我的正则表达式有什么问题?
这里是正则表达式的解释:http://regex101.com/r/rR6uH0/
^ assert position at start of a line
[0-9A-Za-z!@#$^%*_|;:'"`~.,\(\)\{\}\[\]\<\>\\\/\?\-\+\=\&]{6,} match a single character present in the list below
Quantifier: Between 6 and unlimited times, as many times as possible, giving back as needed [greedy]
0-9 a single character in the range between 0 and 9
A-Z a single character in the range between A and Z (case sensitive)
a-z a single character in the range between a and z (case sensitive)
!@#$^%*_|;:'"`~., a single character in the list !@#$^%*_|;:'"`~., literally
\( matches the character ( literally
\) matches the character ) literally
\{ matches the character { literally
\} matches the character } literally
\[ matches the character [ literally
\] matches the character ] literally
\< matches the character < literally
\> matches the character > literally
\\ matches the character \ literally
\/ matches the character / literally
\? matches the character ? literally
\- matches the character - literally
\+ matches the character + literally
\= matches the character = literally
\& matches the character & literally
$ assert position at end of a line
g modifier: global. All matches (don't return on first match)
m modifier: multi-line. Causes ^ and $ to match the begin/end of each line (not only begin/end of string)
【问题讨论】:
-
您到底想“验证”什么?六个或更多非空格 ASCII 可打印字符的简单、直接的正则表达式是
[!-~]{6,},但你为什么不允许密码中的空格?