关于利用正则表达式删指定内容问题
原始代码:
string str = "<td height=20 style=font-size:14px; align=left><span class=Content><a href=/test.php?xxx=xxx target=_blank><font color=#0000FF>测试标题</font></a> </p> </span></td>";
方法1:
System.Text.RegularExpressions.Regex regex1 = new System.Text.RegularExpressions.Regex(@"(<a\s+href\s*=\s*\S+?test.php[^>]+>\s*<[^>]+>)[^<]*(<[^>]*>\s*</a>)", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
string s = regex1.Replace(str, "");
如上写法得到结果:
<td height=20 style=font-size:14px; align=left><span class=Content></p></span></td>";
方法二:
Regex re = new Regex(@"(<a\s+href\s*=\s*\S+?test.php[^>]+>\s*<[^>]+>)[^<]*(<[^>]*>\s*</a>)");
string s = "";
if (re.IsMatch(str))
{
s = re..Replace(str, "$1$2");
}
如上写法得到结果:
<td height=20 style=font-size:14px; align=left><span class=Content><a href=/test.php?xxx=xxx target=_blank><font color=#0000FF></font></a> </p> </span></td>
现在我想得到结果:
"<td height=20 style=font-size:14px; align=left><span class=Content>测试标题 </p> </span></td>";
也就是去掉a 连接HTML标记, 求解, 再次感谢 wackyboy 大哥提供的正则