Support Questions

Find answers, ask questions, and share your expertise

How to use regexp_replace in hive to remove special character ^

avatar
Explorer

I have an expression like

HA^G^FER$$JY

I would like to replace the all ^ with $.

How do I do it. I tried all methods but this isn't working.

Most common error I get is :

java.sql.SQLException: Error while processing statement: FAILED: Execution Error, return code 2 from org.apache.hadoop.hive.ql.exec.mr.MapRedTask

1 ACCEPTED SOLUTION

avatar
Master Guru
@Abhilash Chandrasekharan

Try with the below syntax

hive> select regexp_replace('HA^G^FER$JY',"\\^","\\$");
+---------------+--+
|      _c0      |
+---------------+--+
| HA$G$FER$JY  |
+---------------+--+

As ^,$ are reserved keys for Regex so use two back slashes in regexp_replace function.

View solution in original post

1 REPLY 1

avatar
Master Guru
@Abhilash Chandrasekharan

Try with the below syntax

hive> select regexp_replace('HA^G^FER$JY',"\\^","\\$");
+---------------+--+
|      _c0      |
+---------------+--+
| HA$G$FER$JY  |
+---------------+--+

As ^,$ are reserved keys for Regex so use two back slashes in regexp_replace function.