【发布时间】:2020-12-20 18:40:30
【问题描述】:
SELECT
ocr_text,
bucket,
REGEXP_EXTRACT('-?[0-9]+(\.[0-9]+)?', ocr_text)
FROM temp
我正在尝试从不存在货币的字符串中提取金额。任何没有小数的数字都不应该匹配。假设逗号遵循正确的规则(在数百个标记处),则应允许使用逗号
56 no (missing decimals)
56.45 yes
120 no (missing decimals)
120.00 yes
1200.00 yes
1,200.00 yes
1,200 no (missing decimals)
1200 no (missing decimals)
134.5 no (decimal not followed by 2 digits)
23,00.00 no (invalid comma location)
我是 REGEX 的菜鸟,所以我知道我的上述陈述已经不符合我列出的标准。但是,我已经在我的REGEX_EXTRACT 行上遇到了错误(INVALID_FUNCTION_ARGUMENT) premature end of char-class
有人能指出我正确的方向吗?如何解决我当前的问题?如何修改以正确合并列出的其他标准?
【问题讨论】:
-
公平地说,世界上只有大约五个人懂正则表达式。不要出汗。
-
@CaptainKenpachi Wiktor Stribiżew 可能被认为是五个
:-)之一 -
是的,他来自世界上许多天才的地方。