什么是正则表达式以匹配具有以下模式的单词:
数字或大写字母* 3(最后加+“List”)
例如,
OP3
G6H
ZZAList
349
127List
都是有效的,而
a3G
P-0List
HYiList
def
YHr
都是无效的。
请您参考如下方法:
您可以使用正则表达式:
^[A-Z0-9]{3}(?:List)?$
说明:
^ : Start anchor
[A-Z0-9] : Char class to match any one of the uppercase letter or digit
{3} : Quantifier for previous sub-regex
(?:List) : A literal 'List' enclosed in non-capturing paranthesis
? : To make the 'List' optional
$ : End anchor
See it