【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);
		}

posted @ 2016-08-08 15:14  游子善心  阅读(1)  评论(0编辑  收藏  举报  来源