求助,C#正则匹配 * {margin: 0;padding: 0;}body{background-color:transparent;}body {font: 90%/normal Arial, Helvetica, sans-serif;}a:link {color: #00c;text-decoration: underline;}a:visited {color: #800080;}strong {color: #c03;font-weight: normal;

来源:学生作业帮助网 编辑:作业帮 时间:2024/04/28 22:00:43
求助,C#正则匹配 * {margin: 0;padding: 0;}body{background-color:transparent;}body {font: 90%/normal Arial, Helvetica, sans-serif;}a:link {color: #00c;text-decoration: underline;}a:visited {color: #800080;}strong {color: #c03;font-weight: normal;

求助,C#正则匹配 * {margin: 0;padding: 0;}body{background-color:transparent;}body {font: 90%/normal Arial, Helvetica, sans-serif;}a:link {color: #00c;text-decoration: underline;}a:visited {color: #800080;}strong {color: #c03;font-weight: normal;
求助,C#正则匹配

* {margin: 0;padding: 0;}
body{background-color:transparent;}
body {font: 90%/normal Arial, Helvetica, sans-serif;}
a:link {color: #00c;text-decoration: underline;}
a:visited {color: #800080;}
strong {color: #c03;font-weight: normal;}


主要是想要过滤掉这些代码,但是不知道怎么匹配,求助.
public static string RemoveHtml(string html)
这个测试过了,CSS里面的样式还是没有过滤掉.
有什么办法能直接过滤那些CSS吗?

求助,C#正则匹配 * {margin: 0;padding: 0;}body{background-color:transparent;}body {font: 90%/normal Arial, Helvetica, sans-serif;}a:link {color: #00c;text-decoration: underline;}a:visited {color: #800080;}strong {color: #c03;font-weight: normal;
public static string RemoveHtml(string html)
{
System.Text.RegularExpressions.Regex regex1 = new System.Text.RegularExpressions.Regex(@"",System.Text.RegularExpressions.RegexOptions.IgnoreCase);
System.Text.RegularExpressions.Regex regex7 = new System.Text.RegularExpressions.Regex(@"
",System.Text.RegularExpressions.RegexOptions.IgnoreCase);
System.Text.RegularExpressions.Regex regex8 = new System.Text.RegularExpressions.Regex(@"
",System.Text.RegularExpressions.RegexOptions.IgnoreCase);
System.Text.RegularExpressions.Regex regex9 = new System.Text.RegularExpressions.Regex(@"]*>",System.Text.RegularExpressions.RegexOptions.IgnoreCase);
html = regex1.Replace(html,""); //过滤标记
html = regex2.Replace(html,""); //过滤href=javascript:() 属性
html = regex3.Replace(html," _disibledevent="); //过滤其它控件的on...事件
html = regex4.Replace(html,""); //过滤iframe
html = regex5.Replace(html,""); //过滤frameset
html = regex6.Replace(html,""); //过滤frameset
html = regex7.Replace(html,""); //过滤frameset
html = regex8.Replace(html,""); //过滤frameset
html = regex9.Replace(html,"");
html = html.Replace(" ","");
html = html.Replace("&","&");
html = html.Replace("","");
html = html.Replace("","");
html = html.Replace(">","<");
html = html.Replace("