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. }  
  • 相关阅读:
    ngnix 配置反向代理
    tomcat nio
    spring boot 1
    mongodb 总结
    spring profile 多环境配置管理
    分布式锁实现
    2020真难
    NSRunLoopCommonModes和NSDefaultRunLoopMode区别(Timer)
    数据统计---埋点
    【问题汇总】iOS数据持久化
  • 原文地址:https://www.cnblogs.com/rainbowzc/p/1856688.html
Copyright © 2011-2022 走看看