Jump to content
UBot Underground

Regex to find email addresses at specific domain


Recommended Posts

Man this is driving me nuts. I just need a regex to use in a scrape to find any email address at a particular domain. such as my.dog@specificdomain.com or hasfleas7@SPECIFICDOMAIN.COM

 

I've tried every regex I can think of and I just can't seem to get it quite right.

 

Have I ever mentioned that I hate regex?

Link to post
Share on other sites

It is a lot easier to find a solution if you provide a context in where your problem occurs. (I used to dislike regexps too, then I saw the light. :)  Regexp is God's gift to humanity, the liberator of a lot of problems, the best thing when compared to sliced bread. :)  I still learn a lot, but even on the nub level like where I am, it is simply put FANTASTIC!)

Link to post
Share on other sites

You could use this regex

 

[a-zA-Z0-9\._\-]{3,}(@|AT|\s(at|AT)\s|\s*[\[\(\{]\s*(at|AT)\s*[\]\}\)]\s*)[a-zA-Z]{3,}(\.|DOT|\s(dot|DOT)\s|\s*[\[\(\{]\s*(dot|DOT)\s*[\]\}\)]\s^*)[a-zA-Z]{2,}((\.|DOT|\s(dot|DOT)\s|\s*[\[\(\{]\s*(dot|DOT)\s*[\]\}\)]\s*)[a-zA-Z]{2,})?$

 

 

or this one

 

 

[a-zA-Z0-9\-\_]+\@[a-zA-Z0-9\_]+\.[a-zA-Z0-9\-\_]{2,4}

 

 

 

The top one will allow things like   myemail[dot]domain[dot]com for example as well as the usual  myeamail@domain.com

 

hope that helps

Link to post
Share on other sites
  • 3 weeks later...

Try this:

 

[a-zA-Z0-9\.]*@(specificdomain.com|SPECIFICDOMAIN.COM)

 

I'm toying with this one today, but I run into the problem that the above regex returns "@domain.com" with no prefix when those exist.

Link to post
Share on other sites

None of these regexs are fully correct. There is something called IDNs, which makes it a lot harder. They are not that widely spread,but they do exist.

 

Add to this that there are additional TLDs coming, e.g. .bank, .travel etc. Pure h*ll. :)

Link to post
Share on other sites

None of these regexs are fully correct. There is something called IDNs, which makes it a lot harder. They are not that widely spread,but they do exist.

 

Add to this that there are additional TLDs coming, e.g. .bank, .travel etc. Pure h*ll. :)

 

He wants to match it to a specific domain though so he knows the TLD. But you're right that it's not fully correct. Here is the best version:

 

 

[_a-z0-9-]+(\.[_a-z0-9-]+)*@(?i)specificdomain.com
 
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...