Extract email adresses from text using RegEx c#
This question already has an answer here:
尝试这个
string strRegex = @"[A-Za-z0-9_-+]+@[A-Za-z0-9-]+.([A-Za-z]{2,3})(?:.[a-z]{2})?";
Regex myRegex = new Regex(strRegex, RegexOptions.None);
string strTargetString = @"wjeqklejqwek myEmail@hotmail.com a;lekqlwe anothermail@mail.ru";
foreach (Match myMatch in myRegex.Matches(strTargetString))
{
if (myMatch.Success)
{
// Add your code here
}
}
Your regular expression worked for me if I take out /
& /i
.
[a-z0-9_-+]+@[a-z0-9-]+.([az]{2,3})(?:.[az]{2})?
alternatively, you can also use this...
/^[w-._+%]+@(?:[w-]+.)+[w]{2,6}$/
上一篇: C#电子邮件地址验证