简体   繁体   English

从 SQL 到 Snowflake [^''aZ -] 的正则表达式

[英]Regex expression from SQL to Snowflake [^''a-Z -]

The following code has to be converted to Snowflake SQL. I'm not sure how to convert the regex and also want to know if it means to negate whitespaces, alphabets and hyphen?以下代码必须转换为 Snowflake SQL。我不确定如何转换正则表达式,也想知道它是否意味着否定空格、字母和连字符?

----SQL CODE

UPDATE t1 ASET A.col1 = 'NOT VALID'
FROM t1
INNER JOIN t2 B
ON A.ID=B.ID
WHEREB.name LIKE '%[^''a-Z -]%';

This is what I tried but no idea on regex.这是我尝试过的但对正则表达式一无所知。

UPDATE t1 A
SET A.col1 = 'NOT VALID' 
FROM t2 B
where A.ID=B.ID  AND
      RLIKE (B.name, [^''a-Z -]);   

Some issues:一些问题:

  • "Alphabets" are not matched by aZ (actually, nothing is). “字母表”与aZ不匹配(实际上,什么都不匹配)。 That should be A-Za-z .那应该是A-Za-z
  • The pattern is implicitly "anchored" at both sides, meaning that the whole input has to match the pattern;模式在两侧隐式“锚定”,这意味着整个输入必须匹配模式; not just a substring. You should add .* before and after the negative character class, or use another function, like regexp_instr不仅仅是一个substring。你应该在否定字符class前后添加.* ,或者使用另一个function,比如regexp_instr
  • a regex is a string in Snowflake, so you should wrap it in quotes正则表达式是 Snowflake 中的一个字符串,因此您应该将其用引号引起来

Correction:更正:

RLIKE (B.name, '.*[^''A-Za-z -].*')

Alternatively, you could use REGEXP_INSTR或者,您可以使用REGEXP_INSTR

REGEXP_INSTR (B.name, '[^''A-Za-z -]') > 0

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM