前瞻意味着
展望未来。所以如果你写:
(?=a)
这意味着
a
。有时,例如在检查密码时,您不希望这样做。你想表达的是,在某个地方应该有一个
.因此:
(?=.*a)
b
8
或
@
一
在某处
^ # start a match at the beginning of the string
(?=.*[a-z]) # should contain at least one a-z character
(?=.*[A-Z]) # should contain at least one A-Z character
(?=.*\d) # should contain at least one digit
[a-zA-Z\d]{8,} # consists out of 8 or more characters and only A-Za-z0-9
$ # end the match at the end of the string
没有
.*
,永远不会有匹配的
"^(?=[a-z])(?=[A-Z])(?=\d)[a-zA-Z\d]{8,}$"
指:
^ # start a match at the beginning of the string
(?=[a-z]) # first character should be an a-z character
(?=[A-Z]) # first character should be an A-Z character
(?=\d) # first character should be a digit
[a-zA-Z\d]{8,} # consists out of 8 or more characters and only A-Za-z0-9
$ # end the match at the end of the string
因为没有同时是A-Z字符和数字的字符。这永远不会满足。
-
我们有
不
-
圆点
.
默认情况下是这样的
not
match the new line character
;
-
^[A-Za-z0-9]{8,}$
这意味着您只需验证输入,而不需要新行。