List of utility methods to do Regex String Replace HTML
String | replaceHtml(String html) replace Html String regEx = "<.+?>"; Pattern p = Pattern.compile(regEx); Matcher m = p.matcher(html); String s = m.replaceAll(""); return s; |
String | replaceHtmlEntities(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(""); ... |
String | replaceHtmlEntities(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("", " "); ... |
String | replaceTags(String payload, Map 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)) : ""); ... |
String | replaceTags(String str, Map 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 { ... |
String | replaceTagsUnlessAnchorTagFound(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); ... |