Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

SQL – REGEX Match the whole word if it has an @ symbol in it

So I am using Snowflake and specifically the REGEXP_REPLACE function. I am looking for a Regex expression that will match any word with an @ symbol in it in a text field.

Example:

RAW_DATA CLEANED_DATA
here is a sample and then an email@gmail.com here is a sample and then an xxxxx
abc@test.com xxxxx

What I have tried so far is:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Select regexp_replace('ABC@gmail.com' , '(([a-zA-Z]+)(\W)?([a-zA-Z]+))', 'xxxxxxx') as result;

Result:

xxxxxxx@xxxxxxx.xxxxxxx

>Solution :

You can use

Select regexp_replace('here is a sample and then an email@gmail.com' , '\\S+@\\S+', 'xxxxx') as result;

Here,

  • \S+ – one or more non-whitespace chars
  • @ – a @ char
  • \S+ – one or more non-whitespace chars
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading