-
package kr.ezen.db; public class HTMLUtil { /** * 모든 HTML 태그를 제거하고 반환한다. * * @param html * @throws Exception */ public static String removeTag(String html) throws Exception { return html.replaceAll("<(/)?([a-zA-Z]*)(\\s[a-zA-Z]*=[^>]*)?(\\s)*(/)?>", ""); } public static String removeTag(String html,String tag) throws Exception { return html.replaceAll("<(/)?("+tag+")(\\s"+tag+"*=[^>]*)?(\\s)*(/)?>", ""); } public static void main(String[] args) { String oriText = "<div>Remove Span</div> <span>tag only</span>"; try { System.out.println("1. " + HTMLUtil.removeTag(oriText)); System.out.println("2. " + HTMLUtil.removeTag(oriText,"span")); System.out.println("3. " + HTMLUtil.removeTag(oriText,"div")); } catch (Exception e) { e.printStackTrace(); } } }