Java HTML Filter filterHTML(String s)

Here you can find the source of filterHTML(String s)

Description

Filters out all HTML tags.

License

Open Source License

Parameter

Parameter Description
s the String to filter

Return

the filtered String

Declaration

public static String filterHTML(String s) 

Method Source Code

//package com.java2s;

public class Main {
    /**//from w  ww.j a v a2s  .c  o m
     * Filters out all HTML tags.
     *
     * @param s   the String to filter
     * @return    the filtered String
     */
    public static String filterHTML(String s) {
        if (s == null) {
            return null;
        }

        s = s.replaceAll("<", "");
        s = s.replaceAll(">", "");
        s = s.replaceAll(" ", "");
        s = s.replaceAll("(?s)<[Ss][Cc][Rr][Ii][Pp][Tt].*?>.*?</[Ss][Cc][Rr][Ii][Pp][Tt]>", "");
        s = s.replaceAll("(?s)<[Ss][Tt][Yy][Ll][Ee].*?>.*?</[Ss][Tt][Yy][Ll][Ee]>", "");
        s = s.replaceAll("(?s)<!--.*?-->", "");
        s = s.replaceAll("(?s)<.*?>", "");
        return s;
    }
}

Related

  1. filterHtml(String body)
  2. filterHTML(String input)
  3. filterHTML(String input)
  4. filterHtml(String input)
  5. filterHtml(String s)
  6. filterHtmlAndTruncate(String s)
  7. filterHtmlAndTruncate(String s)
  8. filterHtmlTag(String body)
  9. filterHtmlTag(String content)