【asp.net】 从字符串中抓取邮箱地址
private void GetMail(string txt)
{
List<string[]> list = new List<string[]>();
string text = Regex.Replace(txt, ":", ":");
text = Regex.Replace(text, ",", ",");
text = Regex.Replace(text, "!", "!");
text = Regex.Replace(text, "。", ".");
text = Regex.Replace(text, "《", "<");
text = Regex.Replace(text, "》", ">");
text = Regex.Replace(text, "?", "?");
text = Regex.Replace(text, "“", "\"");
text = Regex.Replace(text, "”", "\"");
text = Regex.Replace(text, "[^\\x00-\\xFF]*", "");
text = text.Replace("#", "@");
Regex regex = new Regex("\\w[\\w\\.-]+?@\\w[\\w-]+?\\.\\w{2,3}(\\.\\w{2,3})*");
MatchCollection matchCollection = regex.Matches(text);
foreach (Match match in matchCollection)
{
string value = match.Value;
bool flag = true;
DataGridView dataGridView = (DataGridView)this.getctl(Application.OpenForms["frmMain"], "dgvMail")[0];
foreach (DataGridViewRow dataGridViewRow in ((IEnumerable)dataGridView.Rows))
{
if (value == dataGridViewRow.Cells["Mail"].Value.ToString())
{
flag = false;
break;
}
}
for (int i = 0; i < list.Count; i++)
{
if (list[i][1] == value)
{
flag = false;
break;
}
}
if (flag)
{
list.Add(new string[]
{
value.Substring(0, value.IndexOf('@')),
value,
this.url
});
}
}
new Thread(new ParameterizedThreadStart(this.AddList))
{
IsBackground = true
}.Start(list);
}
定,精,简,俭