我正在编写一个正则表达式来匹配字符串中的序列递增数字。它在测试中运行良好,但在 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] -----------------------------------------------
最佳答案
Amazon Redshift 正则表达式基于 POSIX ( proof )。 POSIX Basic Regular Expressions不支持 ^(?:[^1]*)1(?:[^2]*)2(?:[^3]*)3(?:.*) 的非捕获组$
表达式包含:有四种 (?:...)
模式。
完全删除这些组,因为您不打算使用它们:
^[^1]*1[^2]*2[^3]*3.*$
关于Amazon Redshift 中匹配序列数字的正则表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63909609/