I\'ve got a list of email addresses belonging to several domains. I\'d like a regex that will match addresses belonging to three specific domains (for this example: foo, bar
Use:
/@(foo|bar|baz)\.?$/i
Note the differences from other answers:
\.?
- matching 0 or 1 dots, in case the domains in the e-mail address are "fully qualified"$
- to indicate that the string must end with this sequence,/i
- to make the test case insensitive.Note, this assumes that each e-mail address is on a line on its own.
If the string being matched could be anywhere in the string, then drop the $
, and replace it with \s+
(which matches one or more white space characters)