我有以下数据,我如何找到第11次出现':'。我想在':'发生第11次后打印/显示信息。正则表达式/ Redshift
我已经试过[^]标签,但它不工作。
select regexp_substr(id,'[:]{5}?.*') from tempnew;
我有以下数据,我如何找到第11次出现':'。我想在':'发生第11次后打印/显示信息。正则表达式/ Redshift
我已经试过[^]标签,但它不工作。
select regexp_substr(id,'[:]{5}?.*') from tempnew;
我会分裂的 “:” 并使用11要素。
但是如果你必须使用正则表达式:
^(?:[^:]*:){10}:([^:]*)
,并使用匹配的组1。
谢谢波希米亚人。 – 2015-03-14 05:49:22
regexp_substr
不关心捕获组,因此不包含在匹配中的字符是不可能的。从最终计数会的工作,虽然:
-- Returns the substring after the 6th ':' from the end.
select regexp_substr(id, '([^:]*:){5}[^:]*$') from tempnew
-- If the string does not contain 5 ':', an empty string is returned.
如果你需要从一开始就来算,你可以使用regexp_replace
代替:
-- Returns the substring after the 11th ':'
select regexp_replace(id, '^([^:]*:){11}') from tempnew
-- If the string does not contain 11 ':', the whole string is returned.
感谢Markus Jarderot ......我工作过。 – 2015-03-13 13:31:20
您可以使用split_part为了这个目的, 选择split_part(ID ,':',12)from tempnew
请包括你想要的结果。 – 2015-03-13 07:41:34