Java Utililty Methods Regex String Replace HTML

List of utility methods to do Regex String Replace HTML

  1. HOME
  2. Java
  3. R
  4. Regex String Replace HTML

Description

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

Method

String removeAllHtmlTag(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();
String removeAllTags(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("");
String removeAllTags(String htmlText)
remove All Tags
String stripped = TAGS_PATTERN.matcher(htmlText).replaceAll("").trim();
return stripped;
String removeAllTags(String input)
remove All Tags
if (input == null || input.trim().length() == 0) {
 return input;
return htmlTagPat.matcher(input).replaceAll("");
String removeTag(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("");
...
String removeTag(String text)
remove Tag
text = replaceConsecutiveSpaces(text, " ");
synchronized (removeScriptObjectStylePattern) {
 text = removeScriptObjectStylePattern.matcher(text).replaceAll("");
synchronized (removeBrPattern1) {
 text = removeBrPattern1.matcher(text).replaceAll("</p>");
synchronized (removeEndTagBlockPattern1) {
...
String removeTags(String html)
remove Tags
Matcher m = _patternTag.matcher(html);
String text = m.replaceAll(" ");
return text;
String removeTags(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;
...
String removeTags(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("");
String replaceHtml(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;
...


AltStyle によって変換されたページ (->オリジナル) /