List of utility methods to do Regex String Replace All
String | replaceAll(String str, String regex, String replacement) Enhances the basic String#replaceAll method by including the Pattern.DOTALL bitmask in the replacement operation. StringBuffer sb = new StringBuffer(); try { Pattern pattern = Pattern.compile(regex, Pattern.DOTALL); Matcher matcher = pattern.matcher(str); while (matcher.find()) { matcher.appendReplacement(sb, replacement); matcher.appendTail(sb); ... |
String | replaceAll(String str, String regex, String replacement) replace All Pattern p = Pattern.compile(regex); Matcher m = p.matcher(str); StringBuffer sb = new StringBuffer(); while (m.find()) { m.appendReplacement(sb, replacement); m.appendTail(sb); return sb.toString(); ... |
String | replaceAll(String string, Pattern pattern, String repalStr) replace All if (string == null) { return null; Matcher m = pattern.matcher(string); if (m.find()) { StringBuffer sb = new StringBuffer(); while (true) { m.appendReplacement(sb, repalStr); ... |
String | replaceAll(String string, Pattern[] patterns, String replacement) replace All if (string == null || string.length() == 0) { return string; if (patterns != null) { for (Pattern pattern : patterns) { string = pattern.matcher(string).replaceAll(replacement); return string; |
String | replaceAll(String target, String from, String to) Replaces the all substrings of this string that matches the given from string with the given replacement. return target.replaceAll(Pattern.quote(from), Matcher.quoteReplacement(to));
|
String | replaceAll(String text, Pattern pattern, String replace) replace All Matcher m = pattern.matcher(text); StringBuffer sb = null; while (m.find()) { if (sb == null) sb = new StringBuffer(); m.appendReplacement(sb, replace); if (sb != null) ... |
StringBuilder | replaceAll(StringBuilder sb, String regex, String replacement) The equivalent of String.replaceAll() for StringBuilder Pattern pattern = Pattern.compile(regex); Matcher m = pattern.matcher(sb); int start = 0; while (m.find(start)) { sb.replace(m.start(), m.end(), replacement); start = m.start() + replacement.length(); return sb; ... |
String | replaceAllBackreference(String text, String regex, String replacement) replace All Backreference Matcher m = createMatcher(text, regex);
text = m.replaceAll(replacement);
return text;
|
String | replaceAllIgnoreCase(String source, String oldstring, String newstring) replace All Ignore Case Pattern p = Pattern.compile(oldstring, 34);
Matcher m = p.matcher(source);
return m.replaceAll(newstring);
|
String | replaceAllLiteral(@Nonnull String value, @Nonnull Pattern pattern, @Nonnull String replace) replace All Literal return pattern.matcher(value).replaceAll(Matcher.quoteReplacement(replace));
|