【问题标题】:Regex pattern for capital letters and numbers only, with possible 'List'仅大写字母和数字的正则表达式模式,可能带有“列表”
【发布时间】:2011-09-11 12:31:30
【问题描述】:

匹配具有该模式的单词的正则表达式是什么:

任意顺序的数字或大写 * 3(+可能的“列表”在末尾)

例如,

OP3
G6H
ZZAList
349
127List

都是有效的,而

a3G
P-0List
HYiList
def
YHr

都是无效的。

【问题讨论】:

    标签: regex numbers capitalization


    【解决方案1】:

    您可以使用正则表达式:

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

    【讨论】:

    • 这是一种享受,感谢您也提供了解释,正则表达式现在对我来说开始更有意义了。虽然不是很多...;P
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多