I have a table of email addresses:
CREATE TABLE contacts(
email VARCHAR(255)
)
INSERT INTO contacts VALUES
('[email protected]'),
('[email protected]'),
('[email protected]');
How can I find and replace the email format so [email protected]
-> [email protected]
?
E.g:
UPDATE contacts
SET email = REGEXP_REPLACE(email, '@', '@test.com');
Results in [email protected]
Playground here: https://dbfiddle.uk/GnIfomiO
2
Answers
This is probably most simply done by splitting the email address in two on the
@
, keeping the part before it and replacing.
in the part after it with nothing. Then you can just append@test.com
to the result:Output for your demo:
Demo on dbfiddle
demo: https://dbfiddle.uk/0KWPVeAI
The regex pattern is @ follow all the chars to end of string