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 } 
  • 相关阅读:
    Excel Sheet Column Number
    HappyNum
    isIsomorphic
    Contains DuplicateII
    iis7 设置http 自动跳转到https
    php 安装redis
    java 打包 war包
    NPOI 操作excel之 将图片插入到指定位置;
    nopi 简洁笔记
    vs11 微软下载地址
  • 原文地址:https://www.cnblogs.com/quchengfeng/p/4598256.html
Copyright © 2011-2022 走看看