【发布时间】:2017-11-28 23:09:13
【问题描述】:
我只使用以下方法从电子邮件正文中捕获所有有效的电子邮件地址。
public static IEnumerable<string> ParseAllEmailAddressess(string data)
{
HashSet<String> emailAddressess = new HashSet<string>();
Regex emailRegex = new Regex(@"\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*", RegexOptions.IgnoreCase);
MatchCollection emailMatches = emailRegex.Matches(data);
foreach (Match emailMatch in emailMatches)
{
emailAddressess.Add(emailMatch.Value);
}
return emailAddressess;
}
这里的问题是 Outlook 将签名图像转换为一些随机的电子邮件地址,例如 (image001.png@01D36870.C9EE4D60) 。我的方法将其视为有效的电子邮件地址并捕获它。我想在解析电子邮件正文时去掉这样的电子邮件地址。
我可以考虑将电子邮件地址拆分为 .在@site 之前并使用第一个索引来匹配图像扩展名“.png”来识别有效的电子邮件。但我认为它不是很有效。应用一些 reg ex 来剥离签名图像内容会很快。
任何帮助将不胜感激。
【问题讨论】:
标签: c# asp.net regex regex-negation regex-group