日期:2014-05-17 浏览次数:20852 次
string str = @"""张三"" <zs@test.com>; ""ZhangYue"" <zhangyue@csdn.com>; ""李四"" <lisi@yoooo.com>; ""小二"" <xr2013@bbbb.com>";
string strmatch = @"""([^""]+)""[^<>]+<([^<>]+)>";
System.Text.RegularExpressions.Regex reg = new System.Text.RegularExpressions.Regex(strmatch);
System.Text.RegularExpressions.MatchCollection mc = reg.Matches(str);
foreach (System.Text.RegularExpressions.Match mm in mc)
{
MessageBox.Show(mm.Groups[1].Value);
MessageBox.Show(mm.Groups[2].Value);
}
string tempStr = File.ReadAllText(@"C:\Users\myx\Desktop\Test.txt", Encoding.GetEncoding("GB2312"));//读取txt
MailAddressCollection mac = new MailAddressCollection();
var _list = Regex.Matches(tempStr, @"(?i)(['""]?)(?<Name>[^'""]*?)\1\s+?\<(?<Adress>[^<>;]+)\>").Cast<Match>().Select(a => new MailAddress(a.Groups["Adress"].Value,a.Groups["Name"].Value));
_list.ToList().ForEach(x=>mac.Add(x));