Android HTML Tag Remove removeTags(final String source, final String regex)

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

Description

remove Tags

Declaration

public static String removeTags(final String source, final String regex) 

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.jav a 2s.  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)