正则表达式是\b(?=.*[A-Z])(?=.*[a-z])(?=.*\d)[a-zA-Z\d]{8,}\b句子是这个句子有一个Goodnight13单词我期望只找到GoodNight13,但我也拿起sentence。如何避免找到sentence?
\b(?=.*[A-Z])(?=.*[a-z])(?=.*\d)[a-zA-Z\d]{8,}\b
GoodNight13
sentence
uxhixvfz1#
您只能匹配A-Za-z和\d,而不是使用.*,并且在Assert时,在匹配之前首先从前导字符类中排除您想要的内容。
A-Z
a-z
\d
.*
\b(?=[a-z\d]*[A-Z])(?=[A-Z\d]*[a-z])(?=[A-Za-z]*\d)[A-Za-z\d]{8,}\b
Regex demo
1条答案
按热度按时间uxhixvfz1#
您只能匹配
A-Z
a-z
和\d
,而不是使用.*
,并且在Assert时,在匹配之前首先从前导字符类中排除您想要的内容。Regex demo