Java removes HTML and CSS styles

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.