Explain, the document content copied from the open source China in the article, because the plagiarism time is too long, has not found the blogger! Temporarily can not explain source, source Bo master See not gas, can contact me!
My blog, the article belongs to the personal collection, in order to solve the urgency of the future!
PackageQ;ImportJava.util.regex.Matcher;ImportJava.util.regex.Pattern; Public classHtmltest {Private Static FinalString regex_script = "<script[^>]*?>[\\s\\S]*?<\\/script>";//to define a regular expression for a script Private Static FinalString Regex_style = "<style[^>]*?>[\\s\\S]*?<\\/style>";//Regular expressions that define a style Private Static FinalString regex_html = "<[^>]+>";//Regular expressions that define HTML tags Private Static FinalString regex_space = "\\s*|\t|\r|\n";//Define a space carriage return line break /** * @paramHtmlstr *@return* Delete HTML tags*/ Public Staticstring Delhtmltag (String htmlstr) {Pattern p_script=pattern.compile (Regex_script, pattern.case_insensitive); Matcher M_script=P_script.matcher (HTMLSTR); Htmlstr= M_script.replaceall ("");//Filter Script 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 TagsPattern P_space=pattern.compile (Regex_space, pattern.case_insensitive); Matcher M_space=P_space.matcher (HTMLSTR); Htmlstr= M_space.replaceall ("");//Filter Blank Enter label returnHtmlstr.trim ();//returns a text string } Public Staticstring gettextfromhtml (String htmlstr) {Htmlstr=Delhtmltag (HTMLSTR); Htmlstr= Htmlstr.replaceall (" ", "" ");//htmlstr = htmlstr.substring (0, Htmlstr.indexof (". ") +1); returnHtmlstr; } Public Static voidMain (string[] args) {String str= "<div style= ' text-align:center; ' > regulation of "Four Winds" to remove the disadvantages of descaling <br/><span style= ' font-size:14px; > </span><span style= ' font-size:18px; ' > Company held the party's mass line education practice activities Mobilization Conference </span><br/><title> I am the title </title><desc> I am desc content </desc ></div> "; SYSTEM.OUT.PRINTLN (gettextfromhtml (str)); }}
Post the result of the final replacement:
Java substitution contains HTML tags