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