Java Removes HTML tags

Source: Internet
Author: User

1 ImportJava.util.regex.Matcher;2 ImportJava.util.regex.Pattern;3 4  Public classhtmlspirit{5      Public Staticstring Delhtmltag (String htmlstr) {6String regex_script= "<script[^>]*?>[\\s\\S]*?<\\/script>";//to define a regular expression for a script7String regex_style= "<style[^>]*?>[\\s\\S]*?<\\/style>";//Regular expressions that define a style8String regex_html= "<[^>]+>";//Regular expressions that define HTML tags9          TenPattern p_script=Pattern.compile (regex_script,pattern.case_insensitive); OneMatcher m_script=P_script.matcher (HTMLSTR); AHtmlstr=m_script.replaceall ("");//Filter Script Tags -           -Pattern p_style=Pattern.compile (regex_style,pattern.case_insensitive); theMatcher m_style=P_style.matcher (HTMLSTR); -Htmlstr=m_style.replaceall ("");//Filter Style Labels -           -Pattern p_html=Pattern.compile (regex_html,pattern.case_insensitive); +Matcher m_html=P_html.matcher (HTMLSTR); -Htmlstr=m_html.replaceall ("");//Filter HTML Tags +  A         returnHtmlstr.trim ();//returns a text string at     }  -}

Java Removes HTML tags

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.