zoukankan      html  css  js  c++  java
  • java 去掉html标签

     1 import java.util.regex.Matcher; 
     2 import java.util.regex.Pattern; 
     3 
     4 public class HTMLSpirit{ 
     5     public static String delHTMLTag(String htmlStr){ 
     6         String regEx_script="<script[^>]*?>[\s\S]*?<\/script>"; //定义script的正则表达式 
     7         String regEx_style="<style[^>]*?>[\s\S]*?<\/style>"; //定义style的正则表达式 
     8         String regEx_html="<[^>]+>"; //定义HTML标签的正则表达式 
     9          
    10         Pattern p_script=Pattern.compile(regEx_script,Pattern.CASE_INSENSITIVE); 
    11         Matcher m_script=p_script.matcher(htmlStr); 
    12         htmlStr=m_script.replaceAll(""); //过滤script标签 
    13          
    14         Pattern p_style=Pattern.compile(regEx_style,Pattern.CASE_INSENSITIVE); 
    15         Matcher m_style=p_style.matcher(htmlStr); 
    16         htmlStr=m_style.replaceAll(""); //过滤style标签 
    17          
    18         Pattern p_html=Pattern.compile(regEx_html,Pattern.CASE_INSENSITIVE); 
    19         Matcher m_html=p_html.matcher(htmlStr); 
    20         htmlStr=m_html.replaceAll(""); //过滤html标签 
    21 
    22         return htmlStr.trim(); //返回文本字符串 
    23     } 
    24 } 
  • 相关阅读:
    LeetCode 128. 最长连续序列
    MySQL的information_schema
    maven项目板块的pom.xml配置
    mybatis打印SQL日志
    MySQL的时间字段转换
    mysql的csv数据导入与导出
    一致性协议
    分布式事务
    事务基本信息
    分布式系统定义及特点
  • 原文地址:https://www.cnblogs.com/quchengfeng/p/4598256.html
Copyright © 2011-2022 走看看