Support Questions
Find answers, ask questions, and share your expertise
Announcements
Alert: Welcome to the Unified Cloudera Community. Former HCC members be sure to read and learn how to activate your account here.

How to use regexp_replace in hive to remove special character ^

Solved Go to solution
Highlighted

How to use regexp_replace in hive to remove special character ^

New Contributor

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

Accepted Solutions

Re: How to use regexp_replace in hive to remove special character ^

Super 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.

1 REPLY 1

Re: How to use regexp_replace in hive to remove special character ^

Super 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.