3 回答

TA贡献1845条经验 获得超8个赞
您可以使用this正则表达式
^(?!^[.])(?!.*[.]$)(?!.*[.]{2})[\w.'-]{1,64}$
正则表达式分解
^ #Start of string
(?!^[.]) #Dot should not be in start
(?!.*[.]$) #Dot should not be in start
(?!.*[.]{2}) #No consecutive two dots
[\w.'-]{1,64} #Match with the character set at least one times and at most 64 times.
$ #End of string
更正您的正则表达式
-
不应介于字符类之间。它表示范围。避免在两者之间使用它[a-zA-Z0-9_]
相当于\w

TA贡献1811条经验 获得超6个赞
这是一个似乎有效的模式:
^(?!.*\.\.)[a-zA-Z0-9_'-](?:[a-zA-Z0-9_'.-]{0,62}[a-zA-Z0-9_'-])?$
以下是正则表达式模式的解释:
^ from the start of the string
(?!.*\.\.) assert that two consecutive dots do not appear anywhere
[a-zA-Z0-9_'-] match an initial character (not dot)
(?: do not capture
[a-zA-Z0-9_'.-]{0,62} match to 62 characters, including dot
[a-zA-Z0-9_'-] ending with a character, excluding dot
)? zero or one time
$ end of the string
添加回答
举报