As shown below:
package com.lyt.base.util;import java.util.regex.Pattern;public class FilterHtmlUtil {public static String Html2Text(String inputString){ String htmlStr = inputString; // String String with html tag String textStr =""; java.util.regex.Pattern p_script; java.util.regex.Matcher m_script; java.util.regex.Pattern p_style; java.util.regex.Pattern p_html; java.util.regex.Matcher m_html; try{ String regEx_script = "<[//s]*?script[^>]*?>[//s//S]*?<[//s]*?//[//s]*?script[//s]*?>"; //Define script's regular expression { or <script[^>]*?>[//s//S]*?<///script> } String regEx_style = "<[//s]*?style[^>]*?>[//s//S]*?<[//s]*?//[//s]*?>"; //Define the regular expression { or <style[^>]*?>[//s//S]*?<///style> } String regEx_html = "<[^>]+>"; //Define the regular expression p_script = Pattern.compile(regEx_script,Pattern.CASE_INSENSITIVE); m_script = p_script.matcher(htmlStr); htmlStr = m_script.replaceAll(""); //Filter script tag p_style = Pattern.compile(regEx_style,Pattern.CASE_INSENSITIVE); m_style = p_style.matcher(htmlStr); htmlStr = m_style.replaceAll(""); //Filter style tag p_html = Pattern.compile(regEx_html,Pattern.CASE_INSENSITIVE); m_html = p_html.matcher(htmlStr); htmlStr = m_html.replaceAll(""); //Filter html tag textStr = htmlStr; }catch(Exception e){ e.printStackTrace(); } return textStr;//Return text string} }The above example of Java filtering html tags to obtain plain text information is all the content I share with you. I hope you can give you a reference and I hope you can support Wulin.com more.