【问题标题】:Regex for match sequence digits in Amazon RedshiftAmazon 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] -----------------------------------------------

【问题讨论】:

    标签: regex amazon-web-services regex-lookarounds regexp-replace


    【解决方案1】:

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

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

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

    【讨论】:

      猜你喜欢
      • 2018-01-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多