你问是不是
可能的
要用正则表达式实现这一点?当然它漂亮吗?这在旁观者的眼里。
您需要一个如下所示的正则表达式(设置大小写无关标志):
^(?=.*\d)(?=.*[a-z])(?=.*[<special symbols here>])(?!<no 3 digits that are consecutive>)(?!<no three letters that are consecutive>).{8}
让我们看看
消极前瞻
(?!<no 3 digits that are consecutive>)
我们可以这样写。
(?!(?:(?=.*0)(?=.*1)(?=.*2))|(?:(?=.*1)(?=.*2)(?=.*3))|(?:(?=.*2)(?=.*3)(?=.*4))|(?:(?=.*3)(?=.*4)(?=.*5))|(?:(?=.*4)(?=.*5)(?=.*6))|(?:(?=.*5)(?=.*6)(?=.*7))|(?:(?=.*6)(?=.*7)(?=.*8))|(?:(?=.*7)(?=.*9)(?=.*9)))
Demo
这个表达式可以用英文写成
冗长的
模式(
re.X
或
re.VERBOSE
)让它自我记录。
(?! # begin negative lookahead
(?: # begin non-capture group
(?=.*0) # match > 0 characters followed by 0 (positive lookahead)
(?=.*1) # match > 0 characters followed by 1
(?=.*2) # match > 0 characters followed by 2
) # end non-capture group
| # or
... similar for (?:(?=.*1)(?=.*2)(?=.*3))
...
) # end negative lookahead
建筑
(?!<no three letters that are consecutive>)
相似(包含23个元素的交替,
a
,
b
和
c
到
x
,
y
和
z
).