简体   繁体   中英

HIVE - Omitting exact bracketed substring from a string field

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.

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)','')

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM