Q:

Locate, regexp_replace UDFs Hive to replace string in a column

I have a table like below
names    age  gender
v_mark   25   male
j_david  26   male
S_Rose   28   Female
mark     21   male

First I need to findout the name values contains "underscore" or not, Then
I need to replace "underscore" with "space" or "comma" the name values based on the specific condition. 
If gender is male, I need to replace "underscore" with space
If gender is female, I need to replace "underscore" with comma.
I did search in google, and I found that I need use Locate (to check the "underscore" is there in the value) and regexp_replace (To replace the underscore with comma based on condition)  I tried When and Case but getting error. Below is my code.
CASE
(
WHEN LOCATE("_",Table1.names)-1 > 0 AND Table1.gender='male'  THEN regexp_replace(T1.names, "_"," ")
WHEN LOCATE("_",Table1.names)-1 > 0 AND Table1.gender='Female'  THEN regexp_replace(T1.names, "_",",")
ELSE Table1.names
END
    ) AS names1

I need the output like 
names1    age  gender
v mark   25   male
j david  26   male
S,Rose   28   Female
mark     21   male

Can anyone help me.

A:

issue is with '('  after case use below code 
CASE
WHEN LOCATE("_",Table1.names)-1 > 0 AND Table1.gender='male'  THEN regexp_replace(T1.names, ""," ")
WHEN LOCATE("",Table1.names)-1 > 0 AND Table1.gender='Female'  THEN regexp_replace(T1.names, "_",",")
ELSE Table1.names
END
    AS names1

