Preface:
1,replaceAll
2, regular expressions
text:
1,replaceAll
/ * * Remove html code string inside. <br> * require data to be standardized, such as greater than the number to be less than complete, otherwise it will be a collective manslaughter. * * @Param Content * Content * @return contents removed * / public static String stripHtml (String Content) { // <P> Replace paragraph wrap content = content.replaceAll ( "<p. *?>", " \ R & lt \ n-" ); // <br> replaced with a new line Content = content.replaceAll (" <br \\ S * /?> "," \ R & lt \ n-" ); // remove further something between <> Content = content.replaceAll ( "\\ <*.?>", "" ); return content; }
2, regular expressions
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> "; // definition of script regular expression String regEx_style =" <style [^ >] *> [\\ s \\ S] * <\\ / style> "?? ; // definition of a regular expression style String regEx_html = "<[^>] +>"; // definition of HTML tags regex the Pattern p_script = of Pattern.compile (regEx_script, Pattern.CASE_INSENSITIVE); Matcher m_script = p_script.matcher(htmlStr); htmlStrM_script.replaceAll = ( ""); // filter script tag the Pattern p_style = of Pattern.compile (regEx_style, Pattern.CASE_INSENSITIVE); Matcher m_style = p_style.matcher (htmlStr); htmlStr = m_style.replaceAll ( ""); // filtered style label the Pattern p_html = of Pattern.compile (regEx_html, Pattern.CASE_INSENSITIVE); Matcher m_html = p_html.matcher (htmlStr); htmlStr = m_html.replaceAll ( ""); // filtered html tag return htmlStr.trim (); / / returns the text string } }
Reference blog:
java remove html tags - big face - blog Park
https://www.cnblogs.com/newsouls/p/3995394.html