zoukankan      html  css  js  c++  java
  • 去掉HTML标记和脚本正则

    1. using System.Text.RegularExpressions;   
    2.   
    3.     
    4.   
    5. public static string NoHTML(string Htmlstring)   
    6. {   
    7.   
    8.         //删除脚本   
    9.         Htmlstring = Regex.Replace(Htmlstring, @"<script[^>]*?>.*?</script>""", RegexOptions.IgnoreCase);   
    10.         //删除HTML   
    11.         Htmlstring = Regex.Replace(Htmlstring, @"<(.[^>]*)>""", RegexOptions.IgnoreCase);   
    12.         Htmlstring = Regex.Replace(Htmlstring, @"([\r\n])[\s]+""", RegexOptions.IgnoreCase);   
    13.   
    14.         Htmlstring = Regex.Replace(Htmlstring, @"-->""", RegexOptions.IgnoreCase);   
    15.   
    16.         Htmlstring = Regex.Replace(Htmlstring, @"<!--.*""", RegexOptions.IgnoreCase);   
    17.   
    18.         Htmlstring = Regex.Replace(Htmlstring, @"&(quot|#34);""\"", RegexOptions.IgnoreCase);   
    19.   
    20.         Htmlstring = Regex.Replace(Htmlstring, @"&(amp|#38);""&", RegexOptions.IgnoreCase);   
    21.   
    22.         Htmlstring = Regex.Replace(Htmlstring, @"&(lt|#60);""<", RegexOptions.IgnoreCase);   
    23.   
    24.         Htmlstring = Regex.Replace(Htmlstring, @"&(gt|#62);"">", RegexOptions.IgnoreCase);   
    25.   
    26.         Htmlstring = Regex.Replace(Htmlstring, @"&(nbsp|#160);"" ", RegexOptions.IgnoreCase);   
    27.   
    28.         Htmlstring = Regex.Replace(Htmlstring, @"&(iexcl|#161);""\xa1", RegexOptions.IgnoreCase);   
    29.   
    30.         Htmlstring = Regex.Replace(Htmlstring, @"&(cent|#162);""\xa2", RegexOptions.IgnoreCase);   
    31.   
    32.         Htmlstring = Regex.Replace(Htmlstring, @"&(pound|#163);""\xa3", RegexOptions.IgnoreCase);   
    33.   
    34.         Htmlstring = Regex.Replace(Htmlstring, @"&(copy|#169);""\xa9", RegexOptions.IgnoreCase);   
    35.   
    36.         Htmlstring = Regex.Replace(Htmlstring, @"&#(\d+);""", RegexOptions.IgnoreCase);   
    37.   
    38.         Htmlstring.Replace("<""");   
    39.   
    40.         Htmlstring.Replace(">""");   
    41.   
    42.         Htmlstring.Replace("\r\n""");   
    43.   
    44.         Htmlstring = HttpContext.Current.Server.HtmlEncode(Htmlstring).Trim();   
    45.   
    46.         return Htmlstring;   
    47.   
    48. }  
  • 相关阅读:
    Btrace
    ThreadPoolExecutor线程池参数设置技巧
    工具篇-NotePad++/JSON格式化
    springcloud-- Alibaba-nacos--支持的几种服务消费方式
    @RequestParam和@RequestBody的区别
    Excel 2013如何判断单元格里是否包含某个字符
    redis 通配符批量删除key
    字节真题 ZJ26-异或:使用字典树代替暴力破解降低时间复杂度
    约瑟夫环问题解决方法时间复杂度分析
    九字真言
  • 原文地址:https://www.cnblogs.com/wuhuisheng/p/1778789.html
Copyright © 2011-2022 走看看