更新时间:2023-02-21 11:46:31
您需要确保模式与整个输入字符串匹配.另外,字母数字和下划线符号可以与\w
匹配,因此正则表达式本身可以大大缩短.
You need to make sure the pattern matches the whole input string. Also, the alphanumeric and an underscore symbols can be matched with \w
, so the regex itself can be considerably shortened.
我建议:
'regex:/^[\w-]*$/'
详细信息:
^
-字符串开头[\w-]*
-零个或多个来自[a-zA-Z0-9_]
范围或-
s $
-字符串结尾.^
- start of string[\w-]*
- zero or more word chars from the [a-zA-Z0-9_]
range or -
s$
- end of string. 为什么比'alpha_dash'
好:您可以进一步自定义此模式.
Why is it better than 'alpha_dash'
: you can further customize this pattern.