Java Regex String Replace replace(String value)

Here you can find the source of replace(String value)

Description

replace

License

Apache License

Declaration

private static String replace(String value) 

Method Source Code

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

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

public class Main {
    private static final Pattern VAR_PTN = Pattern.compile("\\$\\{([^\\}]+)\\}");

    private static String replace(String value) {
        if (value == null)
            return null;
        StringBuffer sb = new StringBuffer(256);
        Matcher m = VAR_PTN.matcher(value);
        while (m.find()) {
            String propValue = System.getProperty(m.group(1));
            if (propValue == null)
                propValue = "";
            m.appendReplacement(sb, Matcher.quoteReplacement(propValue));
        }//from w w  w. j a v  a  2 s  . c o  m
        m.appendTail(sb);
        return sb.toString();
    }
}

Related

  1. replace(String text, String find, String match, boolean useRegex, boolean isCaseSensitive)
  2. replace(String text, String findPattern, String replacePattern)
  3. replace(String text, String targetText, String newText)
  4. replace(String text, String[] searchStrings, String[] replacements)
  5. replace(String val)
  6. replace_values(HashMap values, String str)
  7. replace_with_in(String aStringToReplace, String aNewString, String aString)