Java Regex String Replace replace(String input, Pattern pattern, Function replacementGenerator)

Here you can find the source of replace(String input, Pattern pattern, Function replacementGenerator)

Description

replace

License

Apache License

Declaration

public static String replace(String input, Pattern pattern, Function<Matcher, String> replacementGenerator) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.util.function.Function;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {
    public static String replace(String input, Pattern pattern, Function<Matcher, String> replacementGenerator) {
        StringBuffer sb = new StringBuffer();
        Matcher m = pattern.matcher(input);
        while (m.find()) {
            m.appendReplacement(sb, replacementGenerator.apply(m));
        }/*from   w  w w .  jav a  2s.  c om*/
        m.appendTail(sb);
        return sb.toString();
    }
}

Related

  1. replace(final String regex, final String replacement, final StringBuffer source, boolean all)
  2. replace(final String template, final Map map, final String prefix, final String suffix, boolean useMapForMatching)
  3. replace(Matcher m, String rv, Object value)
  4. replace(Pattern pattern, String src, Function handler)
  5. replace(String content, String name, String value)
  6. replace(String input, Pattern regex, Function converter)
  7. replace(String inputStr, String patternStr, String replacementStr)
  8. replace(String inString, String oldPattern, String newPattern)
  9. replace(String line, String regexp, String replacement)