[a-zA-Z0-9\@\#\$\%\&\*\(\)\-\_\+\]\[\'\;\:\?\.\,\!\^]+$
有效的输出是: reahb543)(*&&!@#$%^kshABmhbahdxb!@$@#%6813741646
这是我的表达方式。但我只需要8 到 32 位的值。
所以一个有效的字符串是:
- 8 到 32 个字符长
- 包括数字、字母、特殊字符
[a-zA-Z0-9\@\#\$\%\&\*\(\)\-\_\+\]\[\'\;\:\?\.\,\!\^]+$
有效的输出是: reahb543)(*&&!@#$%^kshABmhbahdxb!@$@#%6813741646
这是我的表达方式。但我只需要8 到 32 位的值。
所以一个有效的字符串是:
我会改变你的表达方式:
该表达式将:
^(?=(?:\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}$