简体   繁体   English

C#ASP.NET正则表达式控件

[英]C# ASP.NET regular expression control

I want to remove the below style tag code from the HTML and aspx file using a regular expression. 我想使用正则表达式从HTML和aspx文件中删除以下样式标签代码。

<style type="text/css">
    BODY { background-color:white; }
    TH { align:center; background-color:006563; color:white; font-family:arial; font-size:12pt; }
</style>
//Remove scripts
str = Regex.Replace(str, "`<script.*?>`.*?`</script>`", "", RegexOptions.Singleline);  

//Remove CSS styles, if any found
str = Regex.Replace(str, "`<style.*?>`(.| )*?`</style>`", "", RegexOptions.Singleline);

//Remove all HTML tags, leaving on the text inside.
str= Regex.Replace(str, "`<(.| )*?>`", "", RegexOptions.Singleline);

//Remove \r,\t,\n
str= str.Replace("\r", "").Replace("\n", "").Replace("\t", "");

The following regex can be used to remove the style tag from the Html code. 以下正则表达式可用于从HTML代码中删除样式标签。

System.Text.RegularExpressions.Regex.Replace(HtmlData,
                     @"(<style[^*]*</style>)","",
                     System.Text.RegularExpressions.RegexOptions.IgnoreCase);

Check the above code and let me know whether it is fine for you. 检查上面的代码,让我知道是否适合您。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM