Regex syntax in teradata

a 夏天 提交于 2021-02-10 13:09:24

问题


In functions like REGEXP_REPLACE, REGEXP_SIMILAR we need to mention the regular expression for matching a part of the string. Does the regex follow same syntax as that of regex in java or does Teradata have a separate syntax for regular expressions?


回答1:


It's the same as PCRE (C, Java, PHP, Javascript).

For example, let's say you have a bunch of emails and you want just the web domains from that you would use

SELECT RegExp_Replace(email, '^.*@(.*)', '\1', 1, 0, 'i') FROM emails;

You could even add the http:// to the start using the following:

SELECT RegExp_Replace(email, '^.*@(.*)', 'http://\1', 1, 0, 'i') FROM emails;



回答2:


I had the same question and since there was no satisfying answer started to investigate. According to this support forum answer from a Teradata employee, it is POSIX Extended Regular Expressions (ERE) flavor.

I tried to find out what standard TD14.10 is using, I just found it is ANSI SQL 2008 compliant. Which I found have to be POSIX standard for ERE.

I checked other vendors (Oracle) and they have POSIX-ERE with some PCRE extensions. The [:word:] is POSIX non-standard, but some implementations of regexp are understanding it.



来源:https://stackoverflow.com/questions/37696731/regex-syntax-in-teradata

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!