Java Utililty Methods Regex String Replace All

List of utility methods to do Regex String Replace All

Description

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

Method

StringreplaceAll(final String regex, final String replaceWith, final String subject)
a method to do a CASE INSENSITIVE regex search-replace
final Pattern p = Pattern.compile(regex, Pattern.CASE_INSENSITIVE);
final Matcher m = p.matcher(subject);
return m.replaceAll(replaceWith);
StringreplaceAll(final String regex, final String text, final String replacement)
replace All
final Pattern compiledRegex = Pattern.compile(regex, Pattern.CASE_INSENSITIVE);
return compiledRegex.matcher(text).replaceAll(replacement);
StringreplaceAll(Pattern p, String s, String r, Function cb)
Replaces all occurrences of the pattern in this input
Matcher m = p.matcher(s);
while (m.find()) {
    s = m.replaceFirst(String.format(r, cb.apply(m)));
    m = p.matcher(s);
return s;
StringreplaceAll(Pattern pattern, String string, String replacement)
replace All
return pattern.matcher(string).replaceAll(replacement);
StringreplaceAll(String original, String regexWhat, String with)
replace All
Pattern p = Pattern.compile(regexWhat);
Matcher m = p.matcher(original);
return m.replaceAll(with);
StringreplaceAll(String regex, String ment, String str)
replace All
return replaceAll(regex, ment, str, Pattern.CASE_INSENSITIVE);
StringreplaceAll(String regex, String str, Map map)
replace All
String replacement = null;
Matcher m = Pattern.compile(regex).matcher(str);
if (m.find()) {
    replacement = map.get(m.group(1));
return m.replaceAll(replacement);
StringreplaceAll(String regularExpression, String string, String newValue)
replace All
List<String> matches = new ArrayList<String>();
Pattern pattern = Pattern.compile(regularExpression);
Matcher matcher = pattern.matcher(string);
while (matcher.find()) {
    matches.add(matcher.group(1));
for (String item : matches) {
    string = string.replace(item, newValue);
...
StringreplaceAll(String source, Pattern pattern, String replace)
replace All
Matcher matcher;
synchronized (pattern) {
    matcher = pattern.matcher(source);
return matcher.replaceAll(replace);
StringreplaceAll(String str, String originalToken, String replacementToken)
Replaces all occurrances of this originalToken in this string with this replacementToken.
return str.replaceAll(Pattern.quote(originalToken), Matcher.quoteReplacement(replacementToken));