package com.tree.ztree_demo;

import java.util.regex.Matcher;
import java.util.regex.Pattern; public class StringTools { private static final String regEx_script = "<script[^>]*?>[\\s\\S]*?<\\/script>"; // 定义script的正则表达式
private static final String regEx_style = "<style[^>]*?>[\\s\\S]*?<\\/style>"; // 定义style的正则表达式
private static final String regEx_html = "<[^>]+>"; // 定义HTML标签的正则表达式
private static final String regEx_space = "\\s*|\t|\r|\n";//定义空格回车换行符 /**
* @param htmlStr
* @return 删除Html标签
*/
public static String delHTMLTag(String htmlStr) {
Pattern p_script = Pattern.compile(regEx_script, Pattern.CASE_INSENSITIVE);
Matcher m_script = p_script.matcher(htmlStr);
htmlStr = m_script.replaceAll(""); // 过滤script标签 Pattern p_style = Pattern.compile(regEx_style, Pattern.CASE_INSENSITIVE);
Matcher m_style = p_style.matcher(htmlStr);
htmlStr = m_style.replaceAll(""); // 过滤style标签 Pattern p_html = Pattern.compile(regEx_html, Pattern.CASE_INSENSITIVE);
Matcher m_html = p_html.matcher(htmlStr);
htmlStr = m_html.replaceAll(""); // 过滤html标签 Pattern p_space = Pattern.compile(regEx_space, Pattern.CASE_INSENSITIVE);
Matcher m_space = p_space.matcher(htmlStr);
htmlStr = m_space.replaceAll(""); // 过滤空格回车标签
htmlStr = htmlStr.replaceAll("&nbsp;", "");
htmlStr = htmlStr.replaceAll("↵", "");
return htmlStr.trim(); // 返回文本字符串
} }

最新文章

  1. 得静下心来看python了。
  2. struts2学习笔记--使用Validator校验数据
  3. UINavigationController的创建和相关设置---学习笔记四
  4. LINUX的磁盘管理du命令详解
  5. sql2012还原sql2008备份文件语句
  6. POJ 1696 Space Ant --枚举,模拟,贪心,几何
  7. HDU 1312 Red and Black --- 入门搜索 BFS解法
  8. rsync 同步文件
  9. jQuery getJSON() 能给外部变量赋值
  10. nginx负载均衡和反向代理有什么区别
  11. Oracle笔记-表的管理
  12. vmplayer中的fedora20无法进入图形界面
  13. CentOS 7安装Docker
  14. 有趣而又被忽略的Unity技巧
  15. jQuery菜单示例(全选,反选,取消)
  16. APP自动化框架LazyAndroid使用手册(3)--核心API介绍
  17. 利用反射获取数据列+emit生成属性+单例模式
  18. Tensorflow Chapter-6
  19. validating &amp; update ctabfolder css
  20. POJ 3177 Redundant Paths 双联通分量 割边

热门文章

  1. LeetCode--链表3-经典问题
  2. 前端每日实战:62# 视频演示如何用纯 CSS 创作一只蒸锅
  3. qt creator源码全方面分析(3-3)
  4. jsp内置对象(三)-----response对象
  5. 运维介绍以及虚拟机,centos安装
  6. activiti设置customSessionFactories时的一个小坑
  7. django 从零开始 12 快速集合queryset对象
  8. Redis05——Redis Cluster 如何实现分布式集群
  9. python 异步请求
  10. URL及short URL短网址