Regex for email validation

Database
Teradata Employee

Regex for email validation

hi 

 

I have a column name 'comment' with data as shown below 

 

Comment

Ryan Adams - 9999201- Ryan.adams@email.com

 

I want to extract the email address from this column. Is there any generic regular expression available to do this? The same column contains similar data. 

 

Thanks

 


Accepted Solutions
Teradata Employee

Re: Regex for email validation

You might want to extend Geroge's answer to add something to ensure that there is at least one period after the @ too:

e.g.

select 'Ryan Adams - 9999201- Ryan.adams@email.com' as "comment"
,regexp_substr("Comment", '[^\s]*@[^\s]+\.[^\s]+');

NB: You need to comment the column name as it is a Teradata keyword.

1 ACCEPTED SOLUTION
3 REPLIES 3
Teradata Employee

Re: Regex for email validation

select regexp_substr(Comment, '[^\s]*@[^\s]*')

Teradata Employee

Re: Regex for email validation

You might want to extend Geroge's answer to add something to ensure that there is at least one period after the @ too:

e.g.

select 'Ryan Adams - 9999201- Ryan.adams@email.com' as "comment"
,regexp_substr("Comment", '[^\s]*@[^\s]+\.[^\s]+');

NB: You need to comment the column name as it is a Teradata keyword.

Highlighted
Teradata Employee

Re: Regex for email validation

Actually, the solution should read:

select 'Ryan Adams - 9999201- Ryan.adams@email.com' as "comment"      ,regexp_substr("Comment", '[^\s]+@[^\s]+\.[^\s]+');

to ensure there is also always text before the@ too.

And I meant to say quote the column "comment".

Ta