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:
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