1

I'm trying to cleanup my data in a Hive table. I need to replace some characters in a column but I'm unable to figure out how to remove multiple characters at once in using regexp_replace() in Hive SQL.

The below is straightforward and works as expected:

select regexp_replace('abc-de-ghi', '-','');

and outputs: abcdefghi

But I don't know how to clean up a string with different characters in it:

select regexp_replace('abc-de/ghi@jkl:mn#op', <i-dont-know-what-goes-here>,'');

Can someone please help me with this?

1 Answer 1

3

Use '[-/@:#]' template with character set (in the brackets) you want to remove:

select regexp_replace('abc-de/ghi@jkl:mn#op','[-/@:#]','');

Result:

OK
abcdeghijklmnop
Time taken: 4.656 seconds, Fetched: 1 row(s)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.