我的要求是创建一个正则表达式模式,该模式允许长度至少为8的字符串,最大长度为16以外的任何长度。
我尝试使用此^.{8,}$
来要求至少8个字符,但是我对如何更新它感到困惑,因为它可以允许最小长度为8而不是16的长度。
答案 0 :(得分:2)
这可以完成工作:
^(?!.{16}$).{8,}$
说明:
^ : beginning of string
(?! : negative lookahead, zero-length assertion that make sure we don't have
.{16} : 16 characters
$ : end of string
) : end lookahead
.{8,} : any character, at least 8
$ : end of string