The encapsulation method is as follows
Publicstring Delhtmltag (String htmlstr) {string Regex_style= "<style[^>]*?>[\\s\\S]*?<\\/style>";//Regular expressions that define a styleString regex_html= "<[^>]+>";//Regular expressions that define HTML tagsPattern P_style=Pattern.compile (regex_style,pattern.case_insensitive); Matcher M_style=P_style.matcher (HTMLSTR); Htmlstr=m_style.replaceall ("");//Filter Style LabelsPattern p_html=Pattern.compile (regex_html,pattern.case_insensitive); Matcher m_html=P_html.matcher (HTMLSTR); Htmlstr=m_html.replaceall ("");//Filter HTML TagsHtmlstr=htmlstr.replace ("", "" "); Htmlstr=htmlstr.replaceall ("\\s*|\t|\r|\n", "" "); Htmlstr=htmlstr.replace ("", "" "); Htmlstr=htmlstr.replace ("", "" "); Htmlstr=htmlstr.replaceall ("", "" "); returnHtmlstr.trim ();//returns a text string}
This article refers to the article: http://blog.csdn.net/shiyuezhong/article/details/8122861
Java removes HTML and CSS styles