Amazon Redshift 中匹配序列数字的正则表达式

Posted

技术标签:

【中文标题】Amazon Redshift 中匹配序列数字的正则表达式【英文标题】:Regex for match sequence digits in Amazon Redshift 【发布时间】:2021-01-02 16:03:34 【问题描述】:

我正在编写一个匹配字符串中序列递增数字的正则表达式。它在测试中运行良好,但在 Amazon Redshift 中不起作用。 谁能帮帮我

正则表达式:

^(?:[^1]*)1(?:[^2]*)2(?:[^3]*)3(?:.*)$

例如匹配字符串(正确):

123
1331213
12222211323
17397462453
1abcd2abcd3abcd

https://regex101.com/r/zkUMxG/1/

当我在亚马逊使用它时,得到错误:

Error running query: Invalid preceding regular expression prior to repetition operator. The error occurred while parsing the regular expression fragment: '(?>>>HERE>>>:[^1]*)1(?'. DETAIL: ----------------------------------------------- error: Invalid preceding regular expression prior to repetition operator. The error occurred while parsing the regular expression fragment: '(?>>>HERE>>>:[^1]*)1(?'. code: 8002 context: T_regexp_init query: 19124520 location: funcs_expr.cpp:185 process: query1_107_19124520 [pid=15061] -----------------------------------------------

【问题讨论】:

【参考方案1】:

Amazon Redshift 正则表达式基于 POSIX (proof)。 POSIX Basic Regular Expressions 不支持您的 ^(?:[^1]*)1(?:[^2]*)2(?:[^3]*)3(?:.*)$ 表达式包含的非捕获组:有四种 (?:...) 模式。

完全删除这些组,因为您不打算使用它们:

^[^1]*1[^2]*2[^3]*3.*$

【讨论】:

以上是关于Amazon Redshift 中匹配序列数字的正则表达式的主要内容,如果未能解决你的问题,请参考以下文章

如何解决 Amazon Redshift 中的数字溢出问题

在 Amazon Redshift 中检查数字是整数还是浮点数

Amazon redshift 在字符串正则表达式后获取数字

生成带有日期和小时的时间序列并在 Amazon Redshift 中创建表

如何在 Amazon Redshift 中使用 Hibernate 插入实体

Amazon Redshift:当找到的表 id 不匹配时,如何将 `stl_load_errors` 行与正确的表名相关联?