以下に示すように:
パッケージcom.lyt.base.util;インポートjava.util.regex.pattern; public class filterhtmlutil {public static string html2text(string inputstring){string htmlstr = inputstring; // htmlタグを備えた文字列string textstr = ""; java.util.regex.pattern p_script; java.util.regex.matcher m_script; java.util.regex.pattern p_style; java.util.regex.pattern p_html; java.util.regex.matcher m_html; try {string regex_script = "<[// s]*?script [^>]*?> [// s // s]*?<[// s]*?// [// s]*?script [// s]*?>"; //スクリプトの正規表現{または<script [^>]*?> [// s // s]*?</// script>} string regex_style = "<[^>]*?> [// s]*?<[// s]*? //正規表現を定義する{または<style [^>]*?> [// s // s]*?</// style>}文字列regex_html = "<[^>]+>"; //正規表現p_script = pattern.compile(regex_script、pattern.case_insensitive)を定義する; m_script = p_script.matcher(htmlstr); htmlstr = m_script.replaceall( ""); //フィルタースクリプトタグp_style = pattern.compile(regex_style、pattern.case_insensitive); m_style = p_style.matcher(htmlstr); htmlstr = m_style.replaceall( ""); //フィルタースタイルタグp_html = pattern.compile(regex_html、pattern.case_insensitive); m_html = p_html.matcher(htmlstr); htmlstr = m_html.replaceall( ""); // htmlタグtextStr = htmlstrをフィルターします。 } catch(Exception e){e.printstacktrace(); } return textStr; //テキスト文字列を返す}}JavaフィルタリングHTMLタグの上記の例は、プレーンテキスト情報を取得するためのすべてのコンテンツです。参照を提供できることを願っています。wulin.comをもっとサポートできることを願っています。