Search code examples
regexstringhivespace

Hive: remove the special characters and keep the space between the word


enter image description here

I have custom table and there are special characters in this column. I want to remove the special characters and keep the space between the word.

I try this query.

select customer_ID, REGEXP_REPLACE(name, '[^0-9A-Za-z]', '') from customer

But this query removes all special characters and space.

How can I special characters and keep the space between the word in this column?


Solution

  • If you want to keep the whitespaces then you could add that to the negated character class.

    To match the character class one or more times you could add the + sign after the character class.

    [^0-9A-Za-z ]+

    Your query would look like:

    select customer_ID, REGEXP_REPLACE(name, '[^0-9A-Za-z ]+', '') from customer