问题
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