例子 :
string a="<div onclick="javascript:alert('111');"></div>"
我想得到结果:
<div onclick="javascript:alert('111');" ></div>
protected void Page_Load(object sender, EventArgs e)
{
string a = "<p style='font-style: italic' onclick='alert('hacked!!');'>Hello World</p>";
string b =
Regex.Replace(
a,
@"(<[\s\S]*?) on.*?\=(['""])[\s\S]*?\2([\s\S]*?>)",
delegate(Match match)
{
string br = match.Groups[1].Value;
string bbb = match.Groups[2].Value;
return String.Concat(match.Groups[1].Value,match.Groups[3].Value);
}, RegexOptions.Compiled | RegexOptions.IgnoreCase);
Response.Write(b);
}