regex - Redshift/正则表达式(负向前瞻)不起作用

标签 regex amazon-redshift

当我在 redshift 上使用负前瞻(类似于 (?!abc))时, redshift 返回如下错误:

-- Find records that do not start with abc
select * from table_a where column_a ~ '^(?!abc).+$'

Error: PG::InternalError: ERROR: Invalid preceding regular expression prior to repetition operator. The error occured while parsing the regular expression: '^(?>>>HERE>>>!abc).+$'. DETAIL: ----------------------------------------------- error: Invalid preceding regular expression prior to repetition operator. The error occured while parsing the regular expression: '^(?>>>HERE>>>!abc).+$'. code: 8002 context: T_regexp_init query: 1039510 location: funcs_expr.cpp:130

Redshift 似乎无法识别负向前瞻...
有什么方法可以在 Redshift 上使用它吗?

最佳答案

根据。到Amazon Redshift documentation ,可以与 ~ 一起使用的正则表达式操作符符合 POSIX 标准。这意味着没有环顾支持,并且您不能使用 (?!...) ,也不是(?<!...)以这些模式构建。

您似乎想要匹配一个不以模式开头的字符串。在这种情况下,您可以使用否定正则表达式运算符版本 !~ .

where column_a !~ '^abc'

关于regex - Redshift/正则表达式(负向前瞻)不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41022295/

相关文章:

python - 如何修改文件以替换与此模式匹配的字符串

sql - 我可以在Redshift的窗口函数上添加条件吗?

amazon-redshift - 如何在AWS Redshift中向现有表添加排序键

python-3.x - 无效语法 : Create table sortkey auto with initial sortkeys

sql - 为什么 RedShift 不允许键约束?

sql - 向 Redshift 表添加 NOT NULL 列

python - "ReplaceWith"& - 但只是其中的一部分

java - 带有可选分隔符的正则表达式捕获组

ios - 为 $ - NSString 中的文本着色

ios - 从 NSString 中提取数字的最快且最高效的方法是什么?