Java Regex String Replace All replaceAllBackreference(String text, String regex, String replacement)

Here you can find the source of replaceAllBackreference(String text, String regex, String replacement)

Description

replace All Backreference

License

Open Source License

Declaration

public static String replaceAllBackreference(String text, String regex, String replacement) 

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 replaceAllBackreference(String text, String regex, String replacement) {
        Matcher m = createMatcher(text, regex);
        text = m.replaceAll(replacement);

        return text;
    }//from  w  ww  .ja  v  a2s . co m

    /**
     * Given a regex and an input, returns a matcher to match the regex to the
     * input
     * 
     * @param regex
     *            the regular expression
     * @param input
     *            the input char sequence
     * @return the matcher
     */
    public static Matcher createMatcher(CharSequence input, String regex) {
        Pattern p = Pattern.compile(regex);
        Matcher m = p.matcher(input);
        return m;
    }
}

Related

  1. replaceAll(String string, Pattern pattern, String repalStr)
  2. replaceAll(String string, Pattern[] patterns, String replacement)
  3. replaceAll(String target, String from, String to)
  4. replaceAll(String text, Pattern pattern, String replace)
  5. replaceAll(StringBuilder sb, String regex, String replacement)
  6. replaceAllIgnoreCase(String source, String oldstring, String newstring)
  7. replaceAllLiteral(@Nonnull String value, @Nonnull Pattern pattern, @Nonnull String replace)
  8. replaceAllPerLine(Pattern pattern, String value, String replacement)
  9. replaceAllStrictly(String src, String search, String replacement, boolean entirelyMatch, boolean caseSensitive)