Java Utililty Methods Regex String Replace HTML

List of utility methods to do Regex String Replace HTML

Description

The list of methods to do Regex String Replace HTML are organized into topic(s).

Method

StringremoveAllHtmlTag(String str)
remove All Html Tag
Pattern pattern = Pattern.compile(REGULAR_HTML_TAG);
Matcher matcher = pattern.matcher(str);
StringBuffer sb = new StringBuffer();
boolean result1 = matcher.find();
while (result1) {
    matcher.appendReplacement(sb, "");
    result1 = matcher.find();
matcher.appendTail(sb);
return sb.toString();
StringremoveAllTags(String html)
Removes all HTML tags from the input html String.
String pattern = "<[!\\:\\-/A-Z1-9]+( [^>]*)*>";
Pattern p = Pattern.compile(pattern, Pattern.CASE_INSENSITIVE);
Matcher m = p.matcher(html);
return m.replaceAll("");
StringremoveAllTags(String htmlText)
remove All Tags
String stripped = TAGS_PATTERN.matcher(htmlText).replaceAll("").trim();
return stripped;
StringremoveAllTags(String input)
remove All Tags
if (input == null || input.trim().length() == 0) {
    return input;
return htmlTagPat.matcher(input).replaceAll("");
StringremoveTag(String tagname, String xmlstring)
Replaces a tag given by a tagname in an xmlstring.
if (!patterns.containsKey(tagname)) {
    String regex = "(\\<" + tagname + ">.+?\\</" + tagname + ">)";
    Pattern pattern = Pattern.compile(regex, Pattern.DOTALL | Pattern.MULTILINE);
    patterns.put(tagname, pattern);
Matcher matcher = patterns.get(tagname).matcher(xmlstring);
if (matcher.find()) {
    xmlstring = matcher.replaceAll("");
...
StringremoveTag(String text)
remove Tag
text = replaceConsecutiveSpaces(text, " ");
synchronized (removeScriptObjectStylePattern) {
    text = removeScriptObjectStylePattern.matcher(text).replaceAll("");
synchronized (removeBrPattern1) {
    text = removeBrPattern1.matcher(text).replaceAll("</p>");
synchronized (removeEndTagBlockPattern1) {
...
StringremoveTags(String html)
remove Tags
Matcher m = _patternTag.matcher(html);
String text = m.replaceAll(" ");
return text;
StringremoveTags(String input, List knownTagList)
remove Tags
Pattern tag = compile("</?([^\\s>]*)\\s*[^>]*>", CASE_INSENSITIVE);
Matcher matches = tag.matcher(input);
while (matches.find()) {
    if (!knownTagList.contains(matches.group(1))) {
        input = input.replaceAll(quote(matches.group()), "");
return input;
...
StringremoveTags(String string)
Removes tags from a given string and returns the parsed string.
Example tags: , ,

,
...

if (string == null || string.length() == 0)
    return string;
Pattern REMOVE_TAGS = Pattern.compile("<.+?>");
Matcher m = REMOVE_TAGS.matcher(string);
return m.replaceAll("");
StringreplaceHtml(String html)
replace Html
if (isBlank(html)) {
    return "";
String regEx = "<.+?>";
Pattern p = Pattern.compile(regEx);
Matcher m = p.matcher(html);
String s = m.replaceAll("");
return s;
...