日期:2014-05-17 浏览次数:20655 次
<a class="costdown" href="http://order.xiaomi.com/static/re" onclick="_gaq.push(['_trackEvent', '首页广告点击', '官翻版购买通道']);">官翻版购买通道</a>
<a style="margin-left:20px" href="http://www.xiaomi.com/about" >关于小米</a>
string input = @"<a class=""costdown"" href=""http://order.xiaomi.com/static/re"" onclick=""_gaq.push(['_trackEvent', '首页广告点击', '官翻版购买通道']);"">官翻版购买通道</a>
<a style=""margin-left:20px"" href=""http://www.xiaomi.com/about"" >关于小米</a>
";
Dictionary<string, string> dic = new Dictionary<string, string>();
foreach (Match m in Regex.Matches(input, @"(?is)<a\b[^>]*?href=([""']?)([^""']*?)\1[^>]*?>(.*?)</a>"))
{
dic.Add(m.Groups[2].Value, m.Groups[3].Value);
}
foreach (var m in dic)
{
Console.WriteLine(m.Key + "\t" + m.Value);
}
/*
http://order.xiaomi.com/static/re 官翻版购买通道
http://www.xiaomi.com/about 关于小米
*/