国产探花免费观看_亚洲丰满少妇自慰呻吟_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;
     
  }


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 九江县| 句容市| 绍兴市| 泸西县| 如东县| 遂平县| 郑州市| 津南区| 华宁县| 天水市| 高阳县| 星座| 洪泽县| 巴林右旗| 梓潼县| 米易县| 云安县| 凤台县| 永清县| 云龙县| 微博| 云梦县| 贵溪市| 临武县| 平乐县| 车险| 宁蒗| 潞城市| 三明市| 徐闻县| 永昌县| 新化县| 肇东市| 嘉定区| 新竹县| 兴义市| 商水县| 宜兴市| 永平县| 平果县| 汝城县|