亚洲城ca88客户端,亚洲城ca88客户端下载,亚洲城ca88手机客户端下载

Java正则匹配html标签

2017-10-12 10:38:35文章来源:亚洲城ca88客户端热度:

摘要: java正则匹配html标签

package com.test.util; import java.util.regex.Pattern; public class HtmlUtil {/ ** *去除所有HTML标签* @param inputString * @return * / public static String removeHtmlTag(String inputString) else {//含html标签的字符串 String htmlStr = inputString; String textStr =“”; java.util.regex.Pattern p_script; java.util.regex.Matcher m_script; java.util.regex.Pattern p_style; java.util.regex.Matcher m_style; java.util.regex.Pattern p_html; java.util.regex.Matcher m_html; java.util.regex.Pattern p_special; java.util.regex.Matcher m_special; 尝试{ //定义脚本的正则表达式;”; p_script = Pattern.compile(regEx_script,Pattern.CASE_INSENSITIVE); m_script = p_script.matcher(htmlStr); //过滤脚本标签 htmlStr = m_script.replaceAll(“”); p_style = Pattern.compile(regEx_style,Pattern.CASE_INSENSITIVE); m_style = p_style.matcher(htmlStr); //过滤风格标签 htmlStr = m_style.replaceAll(“”); p_html = Pattern.compile(regEx_html,Pattern.CASE_INSENSITIVE); m_html = p_html.matcher(htmlStr); //过滤HTML标签 htmlStr = m_html.replaceAll(“”); p_special = Pattern.compile(regEx_special,Pattern.CASE_INSENSITIVE); m_special = p_special.matcher(htmlStr); //过滤 特殊标签htmlStr = m_special.replaceAll(“”); textStr = htmlStr; } catch(Exception e){ e.printStackTrace(); } return textStr; } } }

编辑:poster

友情链接

 |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |