There are a lot of RegEx variations for retrieving an email address which are different by strictness. Just follow the link and choose appropriate one according to your needs.
http://www.regular-expressions.info/email.html
For most of the needs the next pattern can be used
Regex pattern = new Regex(@"
\b #begin of word
(?<email> #name for captured value
[A-Z0-9._%+-]+ #capture one or more symboles mentioned in brackets
@ #@ is required symbol in email per specification
[A-Z0-9.-]+ #capture one or more symboles mentioned in brackets
\. #required dot
[A-Z]{2,} #should be more then 2 symboles A-Z at the end of email
)
\b #end of word
", RegexOptions.IgnorePatternWhitespace | RegexOptions.IgnoreCase);
var match = pattern.Match(input);
if (match.Success)
{
var result = match.Groups["email"];
}
Keep in mind that this pattern is not 100% reliable. It works perfect with strings like
string input = "This can be recognized as email heymail@gmail.company.com";
But in string
string input = "This can't be recognized as email hey@mail@gmail.com";
It captures "mail@gmail.com" in spite of the fact that this email is incorrect per specification.