Java Regex String Replace All replaceAll(String string, Pattern pattern, String repalStr)

Here you can find the source of replaceAll(String string, Pattern pattern, String repalStr)

Description

replace All

License

Open Source License

Declaration

public static String replaceAll(String string, Pattern pattern, String repalStr) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

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

public class Main {

    public static String replaceAll(String string, Pattern pattern, String repalStr) {
        if (string == null) {
            return null;
        }/* w  w  w .j  av  a  2 s. c o  m*/
        Matcher m = pattern.matcher(string);
        if (m.find()) {
            StringBuffer sb = new StringBuffer();
            while (true) {
                m.appendReplacement(sb, repalStr);
                if (!m.find()) {
                    break;
                }
            }
            m.appendTail(sb);
            return sb.toString();
        }
        return string;
    }
}

Related

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