public static @NonNull String replaceAll(
            final @NonNull String string,
            final @NonNull Pattern pattern,
            final @NonNull Function<@NonNull MatchResult, @NonNull String> replacer
    ) {
        final Matcher matcher = pattern.matcher(string);
        matcher.reset();
        boolean result = matcher.find();
        if (result) {
            final StringBuffer sb = new StringBuffer();
            do {
                final String replacement = replacer.apply(matcher);
                matcher.appendReplacement(sb, replacement);
                result = matcher.find();
            } while (result);
            matcher.appendTail(sb);
            return sb.toString();
        }
        return string;
    }
Replace all matches in a string.

@param string   string to process
@param pattern  replacement pattern
@param replacer replacement function
@return processed string
cloud-core/src/main/java/org/incendo/cloud/util/StringUtils.java