Home > Software engineering >  Extract text after last occurrence of comma in hive
Extract text after last occurrence of comma in hive

Time:10-12

I want to extract everything after last comma

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

I want the result as

tuv
def

CodePudding user response:

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.

CodePudding user response:

Using regexp_extract:

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

Using split:

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