正则表达式检查开头的特定字母加上最多九个数字字符,用于黑斑羚 [关闭]

Posted

技术标签:

【中文标题】正则表达式检查开头的特定字母加上最多九个数字字符,用于黑斑羚 [关闭]【英文标题】:Regexp to check for specifc letters at beguinning plus max of nine numeric characters, for impala [closed] 【发布时间】:2022-01-23 18:39:01 【问题描述】:

我需要一个 regexp/rlike 表达式来验证以下示例的规则。

字符串必须以'TOT'开头,后跟'F''J',最多9个数字字符:

'TOTF5075997'   is valid
'TOTJ897'       is valid
'TOTJ999999999' is valid
'TOTL838'       is invalid

必须在 HIVE/Impala 上都接受正则表达式。 有人可以帮忙吗?

【问题讨论】:

【参考方案1】:
RLIKE '^TOT[FJ]\\d1,9$' 

正则表达式含义:

^        --beginning of the string
TOT      --literally TOT
[FJ]     --F or J
\\d1,9 --min 1 digit, max 9 digits 
$        --end of the string

【讨论】:

以上是关于正则表达式检查开头的特定字母加上最多九个数字字符,用于黑斑羚 [关闭]的主要内容,如果未能解决你的问题,请参考以下文章