首页 新闻 会员 周边

请问 哪位正则大侠 如何过滤onload

0
悬赏园豆:10 [已关闭问题] 关闭于 2009-10-26 11:21

我要过滤掉页面里面的 onload='xxxxxxx' 和onload="xxxx" 这个正则该怎么写呢。

wentmc的主页 wentmc | 初学一级 | 园豆:35
提问于:2009-10-14 10:37
< >
分享
所有回答(2)
0

public static string FilterByHtml(string sHtml)
{
string regex = @"((onload='[\s\S]*)(?<=')|(onload=\"""+@"[\s\S]*)(?<="+"\"))";
System.Text.RegularExpressions.Regex ex = new System.Text.RegularExpressions.Regex(regex, System.Text.RegularExpressions.RegexOptions.IgnoreCase);
string result= System.Text.RegularExpressions.Regex.Replace(sHtml, regex,"[我被过滤了]",System.Text.RegularExpressions.RegexOptions.IgnoreCase);
return result;
}
public static void Main(string[] args)
{
#region FilterScript
string teststring = "<div class=\"question_body\"><p>我要过滤掉页面里面的 onload='xxxxxxx' 和onload=\"xxxx\" 这个正则该怎么写呢。</p></div>";
string result = FilterByHtml(teststring);
Console.WriteLine(result);
#endregion

Console.ReadKey();
}

 

原始字串:

  <div class="question_body">
<p>我要过滤掉页面里面的 onload='xxxxxxx' 和onload="xxxx" 这个正则该怎么写呢。</p>
                    </div>

执行结果:

 

<div class="question_body"><p>我要过滤掉页面里面的 [我被过滤了] 和[我被过滤了] 这个正则该
怎么写呢。</p></div>

邀月 | 园豆:25475 (高人七级) | 2009-10-14 12:01
0
Code
wackyboy | 园豆:190 (初学一级) | 2009-10-15 16:16
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册