아래 그림과 같이 :
package com.lyt.base.util; import java.util.regex.pattern; public class filterhtmlutil {public static string html2text (String inputString) {String htmlstr = inputString; // html 태그 문자열 문자열 문자열 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; {string regex_script = "<[// s]*? script [^>]*?> [// s // s]*? <[// s]*? // [// s]*? script [// s]*?>"; // 스크립트의 정규 표현식 정의 {또는 <script [^>]*?> [// s // s]*? <///cript>} string regex_style = "<[// s]*? style [^>]*?> [// s]*? <[// s]*? // [// s]*?"; // 정의 정의 {또는 <Style [^>]*?> [// s // s]*? </// style>} String 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 (예외 e) {e.printstacktrace (); } return textstr; // return text string}}}일반 텍스트 정보를 얻기 위해 HTML 태그를 필터링하는 Java 필터링의 위의 예는 내가 공유하는 모든 내용입니다. 나는 당신이 당신에게 참조를 줄 수 있기를 바랍니다. 그리고 당신이 wulin.com을 더 지원할 수 있기를 바랍니다.