I am trying to remove the Parenthesis and its contents after a comma for an Employee Name Field.
I cant seem to get the syntax right to remove special characters and numbers AFTER the first comma. Then i would like to rearrange them if possible to show First Name then Last Name.
Employee Name
Doe (Developer), John(123456)
I can get as far as this:
Doe (Developer), John ()
Doe , John
translate(column_1, 'a0123456789', 'a') as employee_name,
regexp_replace(employee_name, '\([^)]*\)')
I’d like to be able to get to
Doe (Developer), John
but the perfect scenario would be
John (Developer) Doe
2
Answers
I think i found an answer. thanks for all the help though! select
replace(translate(employee_name, 'a0123456789', 'a'), '()', '') as employee_name2, split_part(replace(translate(employee_name, 'a0123456789', 'a'), '()', ''),',',2) ||' '|| split_part(replace(translate(employee_name, 'a0123456789', 'a'), '()', ''),',',1) as employee_name3,
from mytable
We can try using
REGEXP_REPLACE
with capture groups:Here is a working regex demo.