I want to match any email address, that contains at least one .
(dot) before the @
sign. The emails have already been validated, so the regex just needs to search for the .
.
I have tried
Regex emailMatcher = new Regex(@"^[a-zA-Z\.']{1,}\.[a-zA-Z\.']{1,}@example\.com$");
But I know that emails can contain more characters than just a-zA-Z\.'
so this won't cover all cases.
Any ideas on how to do it?
Thanks
EDIT:
I'm not trying to validate emails, I already have the emails validated, I just need to select emails, that contain .
before @
sign
Examples that would pass:
[email protected]
[email protected]
Examples that should pass, but wouldn't pass using my current regex
first.last(comment)@example.com
You could do this without a regex
Func<string, bool> dotBeforeAt = delegate(string email)
{
var dotIndex = email.IndexOf(".");
return dotIndex > -1 && (dotIndex < email.IndexOf("@"));
};
...
emails.Where(dotBeforeAt).ToList();
Try it out
I just need to select ones, that contain dot before @ sign
Then there is no point to build a regex that matches valid e-mail addresses. All you need is a regex that sees that there is a dot in front of the @
sign:
(?<=[.][^@]*)@
(?<=[.][^@]*)
is a positive lookbehind construct. It ensures that the @
sign following it is matched only when there is a dot [.]
followed by zero or more non-@
characters in front of it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With