Android HTML Tag Remove removeTags(final String source)

Here you can find the source of removeTags(final String source)

Description

remove Tags

Declaration

public static String removeTags(final String source) 

Method Source Code

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

public class Main {
    public static String removeTags(final String source, final String regex) {
        String modified = new String(source);
        Pattern pattern = Pattern.compile(regex);
        Matcher matcher = pattern.matcher(modified);
        return matcher.replaceAll("");
    }/*from  w  ww. j ava 2  s. c o m*/

    public static String removeTags(final String source) {
        String modified = removeTags(source,
                "<(\"[^\"]*\"|'[^']*'|[^'\">])*>");
        return replaceHTMLTags(modified);
    }

    private static String replaceHTMLTags(final String source) {
        String modified = new String(source);
        return modified.replace("&nbsp;", " ").replace("&lt;", "<")
                .replace("&gt;", ">").replace("&amp;", "&")
                .replace("&quot;", "\"").replace("\n", "");
    }
}

Related

  1. removeTags(String str)
  2. removeTags(final String source, final String regex)