zoukankan      html  css  js  c++  java
  • c# 正则表达式(转)

    1.styleReg:清除样式.如<style>.class{}</style>.全部替换为空.

    2.scriptReg和styleReg同样的道理.

    3.htmlReg :清除html标签的.输入为<div>aaa</div>,结果为:aaa

    4.htmlSpaceReg :html空格&nbsp;替换为空格

    5.spaceReg :把一个以上的空格替换为一个空格.

    1. public string RemoveHtml(string src)  
    2. {  
    3.     Regex htmlReg = new Regex(@"<[^>]+>", RegexOptions.Compiled | RegexOptions.IgnoreCase);  
    4.     Regex htmlSpaceReg = new Regex("\\&nbsp\\;", RegexOptions.Compiled | RegexOptions.IgnoreCase);  
    5.     Regex spaceReg = new Regex("\\s{2,}|\\ \\;", RegexOptions.Compiled | RegexOptions.IgnoreCase);  
    6.     Regex styleReg = new Regex(@"<style(.*?)</style>", RegexOptions.Compiled | RegexOptions.IgnoreCase);  
    7.     Regex scriptReg = new Regex(@"<script(.*?)</script>", RegexOptions.Compiled | RegexOptions.IgnoreCase);  
    8.   
    9.     src = styleReg.Replace(src, string.Empty);  
    10.     src = scriptReg.Replace(src, string.Empty);  
    11.     src = htmlReg.Replace(src, string.Empty);  
    12.     src = htmlSpaceReg.Replace(src, " ");  
    13.     src = spaceReg.Replace(src, " ");  
    14.     return src.Trim();    
    15. }  
  • 相关阅读:
    django高级应用
    python第六章模块
    python第五章函数
    python第四章文件操作
    python第三章数据类型
    python第二章python入门
    python第一章计算机基础
    Python全栈day 05
    Python全栈day 04
    mysql 消息表分区方案
  • 原文地址:https://www.cnblogs.com/rainbowzc/p/1856688.html
Copyright © 2011-2022 走看看