Extract text after last occurrence of comma in hive

Viewed 186

I want to extract everything after last comma

abc,xyz,tuv
abc,123,abc,def

I want the result as

tuv
def
2 Answers

Pls use

substr(col,-1*instr(col,',',-1)+1)

So here instr will find position of comma from end of string. Then substring will pick that many string from end.

Using regexp_extract:

regexp_extract(col,',([^,]+)$',1)

Using split:

split(col,',')[size(split(col,','))-1]
Related