Java Regex String Replace All replaceAll(String str, String regex, String replacement)

Here you can find the source of replaceAll(String str, String regex, String replacement)

Description

replace All

License

Open Source License

Declaration

public static String replaceAll(String str, String regex, String replacement) 

Method Source Code


//package com.java2s;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {

    public static String replaceAll(String str, String regex, String replacement) {
        Pattern p = Pattern.compile(regex);
        Matcher m = p.matcher(str);
        StringBuffer sb = new StringBuffer();
        while (m.find()) {
            m.appendReplacement(sb, replacement);
        }/*from ww w. j a v a  2s  .  c  o m*/
        m.appendTail(sb);
        return sb.toString();
    }
}

Related

  1. replaceAll(String regex, String str, Map map)
  2. replaceAll(String regularExpression, String string, String newValue)
  3. replaceAll(String source, Pattern pattern, String replace)
  4. replaceAll(String str, String originalToken, String replacementToken)
  5. replaceAll(String str, String regex, String replacement)
  6. replaceAll(String string, Pattern pattern, String repalStr)
  7. replaceAll(String string, Pattern[] patterns, String replacement)
  8. replaceAll(String target, String from, String to)
  9. replaceAll(String text, Pattern pattern, String replace)