[英]Regex not allowed Capital letter followed by lower case letters followed by number followed by special character
regex need to match the below format正则表达式需要匹配以下格式
not allow More than two identical characters in a row不允许连续超过两个相同的字符
but we don't want to follow the specific below Patten(Initial cap word, followed by number, followed by special character- (eg,Fall2015!)) means upper case followed by lower case followed by number followed by special character但是我们不想遵循下面的特定 Patten(首字母大写,后跟数字,后跟特殊字符-(例如,Fall2015!))表示大写后跟小写后跟数字后跟特殊字符
(?=.{8,24}$)(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[_.!@$*=-?#])(([A-Za-z0-9_.!@$*=-?#])\2?(?!\2))
It looks like the following should tick your boxes:看起来以下应该勾选您的框:
^(?![A-Z][a-z]+\d+[.!@$*=?#-]$|.*(.)\1\1)(?=.*[A-Z])(?=.*[a-z])(?=.*\d)(?=.*[.!@$*=?#-]).{8,24}$
^
- Start string anchor. ^
- 开始字符串锚。(?!
- A negative lookahead for: (?!
- 对以下内容的负面预测:
[AZ][az]+\d+[.?@$*=?#-]$
- The literal pattern you want to negate: An uppercase letter, 1+ lowercase letters, 1+ numbers and a special char before the string ends. [AZ][az]+\d+[.?@$*=?#-]$
- 你想要取反的文字模式:一个大写字母、1+ 个小写字母、1+ 个数字和字符串结束前的特殊字符.|
- Or: .*(.)\1\1
- Assert position has no following sequence anywhere of three of the same characters: 0+ characters, a 1st capture group and two immediate backreferences to this group. .*(.)\1\1
- 断言 position 没有以下三个相同字符的序列:0+ 个字符、第一个捕获组和对该组的两个直接反向引用。)
- Close negative lookahead. )
- 关闭负前瞻。(?=.*[AZ])
- Positive lookahead to assert an uppercase letter in string. (?=.*[AZ])
- 在字符串中断言大写字母的正向前瞻。(?=.*[az])
- Positive lookahead to assert a lowercase letter in string. (?=.*[az])
- 在字符串中断言小写字母的正向前瞻。(?=.*\d)
- Positive lookahead to assert a number in string. (?=.*\d)
- 在字符串中断言数字的正向前瞻。(?=.*[.?@$*=?#-])
- Positive lookahead to assert a special character in string. (?=.*[.?@$*=?#-])
- 正向预测以断言字符串中的特殊字符。.{8,24}
- Any 8-24 characters other than newline. .{8,24}
- 除换行符以外的任何 8-24 个字符。$
- End string anchor. $
- 结束字符串锚。Try this:尝试这个:
^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[_.!@$*=?#-])(?!.*(.)\1\1)(?!.*[A-Z][a-z]+\d+[_.!@$*=?#-])[\w.!@$*=?#-]{8,24}$
The key changes are:主要变化是:
^
to anchor the expression to start ^
锚定表达式开始(?..*(.)\1\1)
which prevents tripled chars (?..*(.)\1\1)
防止三倍字符(?..*[AZ][az]+\d+[_?!@$*=?#-])
to prevent input like “Fall2015!” (?..*[AZ][az]+\d+[_?!@$*=?#-])
以防止像“Fall2015!”这样的输入[\w.?@$*=,#-]{8,24}$
to restrict input to only these chars and only 8-24 length [\w.?@$*=,#-]{8,24}$
将输入限制为仅这些字符且仅 8-24 长度 Note also the introduction of \d
as shorthand for [0-9]
and \w
as shorthand for [a-zA-Z0-9_]
.还要注意引入
\d
作为[0-9]
的简写和\w
作为[a-zA-Z0-9_]
简写。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.