Redshift/正则表达式(负超前)不起作用 [英] Redshift / Regular Expression (Negative Lookahead) does not work
问题描述
当我在redshift上使用负前瞻(例如(?! abc)
)时,redshift返回如下错误:
When I use negative lookahead (something like (?!abc)
) on redshift,
redshift returns the error like this:
-- Find records that do not start with abc
select * from table_a where column_a ~ '^(?!abc).+$'
错误:PG :: InternalError:错误:重复运算符之前的无效前导正则表达式.解析正则表达式时发生错误:'^(?>>> HERE >>>!abc).+ $'.详细信息:-----------------------------------------------错误:重复运算符之前的无效前置正则表达式.解析正则表达式时发生错误:'^(?>>> HERE >>>!abc).+ $'.代码:8002上下文:T_regexp_init查询:1039510位置:funcs_expr.cpp:130
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上使用它吗?
It looks like Redshift does not recognize negative lookahead...
Is there any way I can use it on Redshift?
推荐答案
Acc.到 Amazon Redshift文档,可以与〜
运算符配合使用的正则表达式符合POSIX标准.这意味着没有环视支持,并且您不能使用(?!...)
,也不能使用(?<!...)
构造成这些模式.
Acc. to the Amazon Redshift documentation, the regular expressions you can use with ~
operator comply with the POSIX standard. That means there is no lookaround support and you cannot use (?!...)
, nor (?<!...)
constructs in these patterns.
如果字符串不是以模式开头,则似乎要匹配它.在这种情况下,您可以使用取反的正则表达式运算符版本!〜
.
It seems that you want to match a string if it does not start with a pattern. In this case, you may use the negated regex operator version, !~
.
where column_a !~ '^abc'
这篇关于Redshift/正则表达式(负超前)不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!