HIVE - Omitting exact bracketed substring from a string field

27 Views Asked by At

I have a string field with records like the following

“Harry Potter (HP) (ab-cd)” “John Doe (ab-cd)” “Richard Smith (RS)” “William Johnson”

I would like to remove the “(ab-cd)” part from all records without removing any other bracketed expressions.

The results should be: “Harry Potter (HP)” “John Doe” “Richard Smith (RS)” “William Johnson”

I think regexp_replace() needs to be used; but I am not good with regular expressions.

1

There are 1 best solutions below

0
Koushik Roy On

use simple replace() if you are not replacing a pattern. You dont have to use slow & complex regex.

select replace('Harry Potter (HP) (ab-cd)','(ab-cd)','')

enter image description here