HTML 태그 제거하기 2

import java.util.regex.Pattern;

public class HtmlTagDelDecoder {
    private static Pattern HTML_SCRIPT = Pattern.compile("\\]*?>.*?\\<\\/script\\>", Pattern.CASE_INSENSITIVE);
    private static Pattern HTML_STYLE = Pattern.compile("\\]*?>.*?\\<\\/style\\>", Pattern.CASE_INSENSITIVE);
    private static Pattern HTML_OPTION = Pattern.compile("\\]*?>.*?\\<\\/option\\>", Pattern.CASE_INSENSITIVE);
    private static Pattern HTML_TAG = Pattern.compile("\\<.*?\\>", Pattern.CASE_INSENSITIVE);


    /**
     * HTML의 모든 태그를 제거하고 내용만 가져옴
     * 필요에 따라서 부분적인 제거가 가능함
     *
     * @param html string
     * @return html string removed all tags
     */

    private String stripTag( String html )
    {
        html = HTML_SCRIPT.matcher(html).replaceAll("");
        html = HTML_STYLE.matcher(html).replaceAll("");
        html = HTML_OPTION.matcher(html).replaceAll("");
        html = HTML_TAG.matcher(html).replaceAll("");
        html = html.trim();
        return html;
    }
}

--------------------------------
테그 제거하기 1 도 99 % 이상 제거 가능한데.. 이건  1.4 이상버전에서만 사용가능. ㅎ


이 포스팅은 쿠팡 파트너스 활동의 일환으로, 이에 따른 일정액의 수수료를 제공받고 있습니다.

이 포스팅은 제휴마케팅이 적용되어 작성자에게 일정액의 커미션이 제공될수 있습니다.

이 글을 공유하기

댓글

Designed by JB FACTORY

"웨딩박람회 일정 스드메 견적 웨딩플랜닷컴 "

주부알바 재택부업 앙팡펫파트너스

서민안심전환대출 ㅣ정부지원대출ㅣ채무통합대환대출