日期:2014-05-18 浏览次数:20769 次
string a = "<a id=\"t1\" class=link_blue href=\"http://article.ednchina.com/Commu/20071219071733.htm\"> Infonetics:WiMAX设备销售额上升势头增强 </a> "; string reValue = "1212"; string reValue1 = "CSDN"; string regex1 = "(?<=<a[\\s\\S]*?href=\")[^\"']*?(?=\"[^>]*?>)"; string regex2 = "(?<=<a[^>]+?>)[^<]*?(?=\\</a>)"; string result = Regex.Replace(a, regex1,reValue); result = Regex.Replace(result, regex2, reValue1); MessageBox.Show(result);
------解决方案--------------------
给要捕获的组命名就是了:
result = Regex.Replace(result, @"(?<text1><a(?=[^<>]*?id=""t1"").*?href="")[^""]*(?<text2>""[^>]*>)[\s\S]*?(?=</a>)", string.Format("${text1}{0}${text2}{1}", textBox12.Text, textBox11.Text), RegexOptions.IgnoreCase);