0

I'm trying to create a regular expression which will work on an email. I need to match that an email is either from a certain domain or from a certain domain and subdomain. A domain must be matched precisely.

I have this:

@.*\.?somedomain\.com$

Yes, this will match:

  fdsafd@a1.somedomain.com
  fdsafd@somedomain.com
  fdsafd@aabbddjjj.somedomain.com

which is what I need. However, it'll also a domain which contains somedomain.com as a part in it, and this isn't what I want:

fdsafd@partsomedomain.com

I want the domain somedomain.com to be matched precisely.

How to fix it?

kosmosu
  • 63
  • 1
  • 1
  • 6

2 Answers2

1

I would match the following :

@(.*\.)?somedomain\.com$

somedomain is guaranteed to be a whole DN path rather than part of one as it either follows the ending . of the optional group or the @ that precedes it.

Aaron
  • 24,009
  • 2
  • 33
  • 57
0

Try below:

\w+\.com

It will select .com and the word preceding it.

Homer
  • 424
  • 3
  • 7