gpt4 book ai didi

匹配 4 组字母/数字的正则表达式,用连字符分隔

转载 作者:行者123 更新时间:2023-12-05 08:21:19 27 4
gpt4 key购买 nike

我需要一个匹配这个模式的正则表达式(大小写无关紧要):

066B-E77B-CE41-4279

4 组字母或数字,每组 4 个字符,每组之间有连字符。

如有任何帮助,我们将不胜感激。

最佳答案

^(?:\w{4}-){3}\w{4}$

解释:

    ^                  # 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

这将是我最好的选择。然后你可以使用Regex Match (static) .

附言可以找到有关正则表达式的更多信息 here .

附言如果您不想匹配下划线,可以将上面的 \w 替换(两次)为 [a-zA-Z0-9] (称为类匹配大小写字母和数字)。例如

^(?:[a-zA-Z0-9]{4}-){3}[a-zA-Z0-9]{4}$

关于匹配 4 组字母/数字的正则表达式,用连字符分隔,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6699294/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com