国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > HTML > 正文

利用正則表達式去掉html代碼

2024-08-26 00:15:37
字體:
來源:轉載
供稿:網友

using system.text.regularexpressions;//需要引用

  // 利用正則表達式去掉"<"和">"之間的內容
  private string stripht(string strhtml)
  {
   regex regex=new regex("<.+?>",regexoptions.ignorecase);
   string stroutput=regex.replace(strhtml,"");
   return stroutput;
  }


//方法二(不知為什么此方法占用cpu100%)

public static string drophtml(string strhtml)
  {
   string [] aryreg ={
          @"<script[^>]*?>.*?</script>",
          @"<(///s*)?!?((/w+:)?/w+)(/w+(/s*=?/s*(([""''])(//[""''tbnr]|[^/7])*?/7|/w+)|.{0})|/s)*?(///s*)?>",
          @"([/r])[/s]+",
          @"&(quot|#34);",
          @"&(amp|#38);",
          @"&(lt|#60);",
          @"&(gt|#62);",
          @"&(nbsp|#160);",
          @"&(iexcl|#161);",
          @"&(cent|#162);",
          @"&(pound|#163);",
          @"&(copy|#169);",
          @"&#(/d+);",
          @"-->",
          @"<!--.*"        
         };

   string [] aryrep = {
           "",
           "",
           "",
           "/"",
           "&",
           "<",
           ">",
           " ",
           "/xa1",//chr(161),
           "/xa2",//chr(162),
           "/xa3",//chr(163),
           "/xa9",//chr(169),
           "",
           "/r",
           ""   
          };

   string newreg =aryreg[0];
   string stroutput=strhtml;
   for(int i = 0;i<aryreg.length;i++)
   {
    regex regex = new regex(aryreg[i],regexoptions.ignorecase );
    stroutput = regex.replace(stroutput,aryrep[i]);
   }

   stroutput.replace("<","");
   stroutput.replace(">","");
   stroutput.replace("/r","");
   return stroutput;
     
  }


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 都兰县| 和顺县| 宝丰县| 太白县| 乐东| 尉氏县| 莱芜市| 宁波市| 邵阳县| 望城县| 盐津县| 阳山县| 安徽省| 勃利县| 华阴市| 乐业县| 阿图什市| 崇州市| 黑水县| 瑞安市| 英山县| 建水县| 霸州市| 桑植县| 西充县| 乐东| 云阳县| 子洲县| 喜德县| 黎平县| 甘洛县| 齐河县| 靖江市| 兴安盟| 民勤县| 恩施市| 监利县| 攀枝花市| 洛浦县| 伊宁县| 从江县|