PDA

View Full Version : Pulling email domain name all characters after @ sign


dprichard
05-13-2008, 04:17 PM
I have a field in the database that stores the email addresses. I need to just pull the domain names in with my query. I was looking through the string functions, but didn't see one that I could do this with. Does anyone know of one where I can say return everything to the right of the @ sign? There are several different email domains so they vary in length.

Thanks for any help on this.

dprichard
05-13-2008, 05:04 PM
I figured it out based on SUBSTRING AND LOCATE.

SUBSTRING(email FROM (LOCATE('@', email)))

I used locate to find the number of characters into the string that the email @ sign was at and then used SUBSTRING to pull the characters from that character on.

derzok
05-13-2008, 05:08 PM
Are you using straight SQL or are you using a scripting/programming language in combination? I would assume you're using perl or php. In that case, you could easily write a regular expression that would capture all the text after the @

http://www.regular-expressions.info/email.html