我有以下數據,我如何找到第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