[a-zA-Z0-9\@\#\$\%\&\*\(\)\-\_\+\]\[\'\;\:\?\.\,\!\^]+$
有效的输出是:reahb543)(*&&!@#$%^kshABmhbahdxb!@$@#%6813741646
这是我的表达方式。但我需要的值仅为 8到32位。
所以有效的字符串是:
答案 0 :(得分:4)
我会在你的表达中改变一些事情:
此表达式将:
^(?=(?:\D*?\d){8,32}(?!.*?\d))[a-zA-Z0-9@\#$%&*()_+\]\[';:?.,!^-]+$
NODE EXPLANATION
--------------------------------------------------------------------------------
^ the beginning of the string
--------------------------------------------------------------------------------
(?= look ahead to see if there is:
--------------------------------------------------------------------------------
(?: group, but do not capture (between 8 and
32 times (matching the most amount
possible)):
--------------------------------------------------------------------------------
\D*? non-digits (all but 0-9) (0 or more
times (matching the least amount
possible))
--------------------------------------------------------------------------------
\d digits (0-9)
--------------------------------------------------------------------------------
){8,32} end of grouping
--------------------------------------------------------------------------------
(?! look ahead to see if there is not:
--------------------------------------------------------------------------------
.*? any character except \n (0 or more
times (matching the least amount
possible))
--------------------------------------------------------------------------------
\d digits (0-9)
--------------------------------------------------------------------------------
) end of look-ahead
--------------------------------------------------------------------------------
) end of look-ahead
--------------------------------------------------------------------------------
[a-zA-Z0- any character of: 'a' to 'z', 'A' to 'Z',
9@\#$%&*()_+\]\[';:? '0' to '9', '@', '\#', '$', '%', '&', '*',
.,!^-]+ '(', ')', '_', '+', '\]', '\[', ''', ';',
':', '?', '.', ',', '!', '^', '-' (1 or
more times (matching the most amount
possible))
--------------------------------------------------------------------------------
$ before an optional \n, and the end of the
string
<强>样品强>
reahb)(*&&!@#$%^kshABmhbahdxb!@$@#%1234567 = bad
reahb)(*&&!@#$%^kshABmhbahdxb!@$@#%12345678 = good
1234reahb)(*&&!@#$%^kshABmhbahdxb!@$@#%5678 = good
1234reahb)(*&&!@#$%^kshABmhbahdxb!@$@#%5678901234567890123456789012 = good
1234reahb)(*&&!@#$%^kshABmhbahdxb!@$@#%56789012345678901234567890123 = bad
reahb)(*&&!@12345678901234567890123456789012#$%^kshABmhbahdxb!@$@#% = good
reahb)(*&&!@123456789012345678901234567890123#$%^kshABmhbahdxb!@$@#% = bad
如果你想从你的角色类中只允许任何类型的8-32个字符,那么就可以了:
^[a-zA-Z0-9@\#$%&*()_+\]\[';:?.,!^-]{8,32}$