我需要一个与此模式匹配的正则表达式(大小写无关紧要):
066B-E77B-CE41-4279
4组字母或数字每组4个字符长,每组之间用连字符.
任何帮助将不胜感激.
^(?:\w{4}-){3}\w{4}$
Run Code Online (Sandbox Code Playgroud)
说明:
^ # must match beginning of string
(?: # make a non-capturing group (for duplicating entry)
\w{4} # a-z, A-Z, 0-9 or _ matching 4 times
- # hyphen
){3} # this group matches 3 times
\w{4} # 4 more of the letters numbers or underscore
$ # must match end of string
Run Code Online (Sandbox Code Playgroud)
这是我最好的选择.然后你可以使用Regex Match(静态).
PS关于正则表达式的更多信息可以在这里找到.
PPS如果您不想匹配下划线,则\w可以使用[a-zA-Z0-9](以下称为匹配小写和大写字母和数字的类)替换上述内容(两次).例如
^(?:[a-zA-Z0-9]{4}-){3}[a-zA-Z0-9]{4}$
Run Code Online (Sandbox Code Playgroud)