Java Regex String Replace All replaceAll(String regex, String str, Map map)

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

Description

replace All

License

Apache License

Declaration

public static String replaceAll(String regex, String str, Map<String, String> map) 

Method Source Code


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

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

public class Main {
    public static String replaceAll(String regex, String str, Map<String, String> map) {

        String replacement = null;

        Matcher m = Pattern.compile(regex).matcher(str);

        if (m.find()) {

            replacement = map.get(m.group(1));

        }//from w  w w  .j av  a 2 s  .c  o m
        return m.replaceAll(replacement);
    }
}

Related

  1. replaceAll(final String regex, final String text, final String replacement)
  2. replaceAll(Pattern p, String s, String r, Function cb)
  3. replaceAll(Pattern pattern, String string, String replacement)
  4. replaceAll(String original, String regexWhat, String with)
  5. replaceAll(String regex, String ment, String str)
  6. replaceAll(String regularExpression, String string, String newValue)
  7. replaceAll(String source, Pattern pattern, String replace)
  8. replaceAll(String str, String originalToken, String replacementToken)
  9. replaceAll(String str, String regex, String replacement)