filter Html from String via Regex - Java java.util.regex

Java examples for java.util.regex:Match HTML

Description

filter Html from String via Regex

Demo Code


//package com.java2s;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {
    private final static String regxpForHtml = "<([^>]*)>";

    public static String filterHtml(String str) {
        Pattern pattern = Pattern.compile(regxpForHtml);
        Matcher matcher = pattern.matcher(str);
        StringBuffer sb = new StringBuffer();
        boolean result1 = matcher.find();
        while (result1) {
            matcher.appendReplacement(sb, "");
            result1 = matcher.find();// w w  w .j  a  v a 2  s.c  om
        }
        matcher.appendTail(sb);
        return sb.toString();
    }
}

Related Tutorials