java字符串去除html标签
来源:互联网 发布:阿里云个人免费套餐 编辑:程序博客网 时间:2024/05/22 03:14
第一种:
字符串 名字.replaceAll("<.*?>","")
第二种不建议使用:
String str = input.replaceAll("\\&[a-zA-Z]{1,10};", "").replaceAll(
"<[^>]*>", "");
"<[^>]*>", "");
// 去掉所有html元素,
String str = input.replaceAll("<[a-zA-Z]+[1-9]?[^><]*>", "")
.replaceAll("</[a-zA-Z]+[1-9]?>", "");
String str = input.replaceAll("<[a-zA-Z]+[1-9]?[^><]*>", "")
.replaceAll("</[a-zA-Z]+[1-9]?>", "");
第三种:
import java.util.regex.Matcher;import java.util.regex.Pattern; public class HTMLSpirit{ public static String delHTMLTag(String htmlStr){ String regEx_script="<script[^>]*?>[\\s\\S]*?<\\/script>"; //定义script的正则表达式 String regEx_style="<style[^>]*?>[\\s\\S]*?<\\/style>"; //定义style的正则表达式 String regEx_html="<[^>]+>"; //定义HTML标签的正则表达式 Pattern p_script=Pattern.compile(regEx_script,Pattern.CASE_INSENSITIVE); Matcher m_script=p_script.matcher(htmlStr); htmlStr=m_script.replaceAll(""); //过滤 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标签 return htmlStr.trim(); //返回文本字符串 } public static String delSpace(String htmlStr){ htmlStr = htmlStr.replaceAll("\n", ""); htmlStr = htmlStr.replaceAll("\t", ""); return htmlStr.trim(); //返回文本字符串 }}
0 0
- java字符串去除html标签
- java去除html标签
- java去除HTML标签
- 去除字符串中的HTML标签
- 去除字符串中的html标签
- 去除字符串中的HTML标签
- 去除字符串中的html标签
- java使用正则表达式去除字符串的html标签
- java去除字符串中的html标签的方法
- java 后台去除HTML标签
- Java String去除HTML标签
- 去除指定字符串中的HTML标签
- C#去除字符串中的html标签
- PHP去除字符串中的html标签
- C#去除指定字符串中的HTML标签
- 使用RegularExpressions去除HTML标签的字符串
- ASP.NET 去除字符串html样式标签
- SQL去除字符串中HTML标签
- 打开 bs4 之门
- QT写一个记事本⑨
- CCF NOI1076 进制转换
- Fantasy of a Summation
- docker-docker swarm mode 的技术性总结
- java字符串去除html标签
- 虚拟币开发知识(什么是虚拟币时间戳服务)
- 机器人智能回复 智能聊天 朋友圈 加粉 采集ID
- numpy总结帖【json和txt的保存】
- Spark性能调优2-总结分享
- JYX梦——Android开发——博客之始
- Linux命令之exit介绍
- cglib 动态代理
- CSS background-position 背景定位的用法