我正在尝试编写正则表达式来验证令牌
my token has a following structure
:
digits
small alpha
special characters
upper alpha
(可选?
)可能存在或不存在李>注意:可选的[A-Z]字符可能存在于某些令牌中,也可能不存在于某些令牌中,当它存在于令牌中时,应该在5 or more
次之间
minimum of 6 to a max of 30
变化few examples of valid/invalid matches:
token1 : t4xa@ui13p#o6
breakdown : there are 7 [a-z] , 2 special chracter[@#] , 4 digits [0-9]
VALID MATCH: True
token2: 3@piy13Qx9#13@z1337
breakdown: there are 5 [a-z] , 3 special character [@#] , 10 digits [0-9] and 1 [A-Z](which is optional)
VALID MATCH: False (because `[A-Z]` exist in token but it exist for `1` time, it should exist atleast of 5 or more.)
token3: 3@piy1ABC3Qx9#13@DEGFz1337
breakdown: there are 5[a-z], 7 [A-Z] , 10 digits [0-9]
VALID MATCH: True
^(?=.*[\d])(?=.*[A-Z])(?=.*[a-z])(?=.*[@#])[\w\d@#]{6,30}$
如果有0个或5个以上的大写字符,那么可以使用正向前瞻来断言没有大写字符或至少5次
您可以使用取反的字符类和量词来检查出现的最小数量
Regex demo
相关问题 更多 >
编程相关推荐