Import Java. util. regEx. matcher; import Java. util. regEx. pattern; public class htmlspirit {public static string delhtmltag (string htmlstr) {string regex_script = "<SCRIPT [^>] *?> [\ S] *? <\\/ SCRIPT> "; // define the regular expression string regex_style =" <style [^>] *?> [\ S] *? <\\/ Style> "; // define the regular expression string regex_html =" <[^>] +> "; // define the Regular Expression Pattern p_script = pattern for HTML tags. compile (regex_script, pattern. case_insensitive); matcher m_script = p_script.matcher (htmlstr); htmlstr = m_script.replaceall (""); // filter the script tag pattern p_style = pattern. compile (regex_style, pattern. case_insensitive); matcher m_style = p_style.matcher (htmlstr); htmlstr = m_style.replaceall (""); // filter the style label pattern p_html = pattern. compile (regex_html, pattern. case_insensitive); matcher m_html = p_html.matcher (htmlstr); htmlstr = m_html.replaceall (""); // filter the HTML Tag return htmlstr. trim (); // returns a text string }}
Original address http://hi.baidu.com/gs586169/item/7f960d96dd603116924f4189