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

StringreplaceHtml(String html)
replace Html
String regEx = "<.+?>";
Pattern p = Pattern.compile(regEx);
Matcher m = p.matcher(html);
String s = m.replaceAll("");
return s;
StringreplaceHtmlEntities(final String text)
Replaces HTML entities such as ̣ with the corresponding characters.
String t = text;
StringBuilder result = new StringBuilder();
do {
    Matcher matcher = HTML_ENTITIES.matcher(t);
    if (matcher.find()) {
        result.append(matcher.group(1));
        result.append((char) Integer.parseInt(matcher.group(2)));
        t = matcher.replaceFirst("");
...
StringreplaceHtmlEntities(String aText, boolean preserveFormatting)
Replaces all HTML entities ( <, & ), with their Unicode characters.
StringBuffer result = new StringBuffer();
Map<String, String> replacements = new HashMap<String, String>(REPLACEMENTS);
Matcher matcher;
if (preserveFormatting) {
    matcher = SPECIAL_CHAR_NO_WHITESPACE.matcher(aText);
} else {
    matcher = SPECIAL_CHAR_WHITESPACE.matcher(aText);
    replacements.put("", " ");
...
StringreplaceTags(String payload, Map tags)
Replace @tag@ tokens in payload with values from tags map.
final Pattern p = Pattern.compile("@(\\w+)@");
final Matcher m = p.matcher(payload);
String processedPayload = payload;
boolean result = m.find();
if (result) {
    final StringBuffer sb = new StringBuffer();
    do {
        m.appendReplacement(sb, tags.containsKey(m.group(1)) ? tags.get(m.group(1)) : "");
...
StringreplaceTags(String str, Map tags)
replace Tags
StringBuffer ret = new StringBuffer();
Matcher matcher = patternTag.matcher(str);
while (matcher.find()) {
    String tag = matcher.group(1);
    String repl = tags.get(tag);
    if (repl == null) {
        matcher.appendReplacement(ret, "<" + tag + ">");
    } else {
...
StringreplaceTagsUnlessAnchorTagFound(String wikiString, String searchPattern, String replacementPattern)
replace Tags Unless Anchor Tag Found
boolean codeTagsFound = stringContainsPattern(wikiString, searchPattern);
boolean hrefTagsFound = wikiString.contains("[["); 
if (codeTagsFound && hrefTagsFound) {
    return wikiString; 
} else if (codeTagsFound) {
    aPattern = Pattern.compile(searchPattern);
    aMatcher = aPattern.matcher(wikiString);
    return aMatcher.replaceAll(replacementPattern);
...