Archives of Support Questions (Read Only)

This is an archived board for historical reference. Information and links may no longer be available or relevant
Announcements
This board is archived and read-only for historical reference. To ask a new question, please post a new topic on the appropriate active board.

How to use regexp_replace in hive to remove special character ^

avatar
New Member

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.