Here you can find the source of replace(String val)
Parameter | Description |
---|---|
val | a parameter |
public static String replace(String val)
//package com.java2s; import java.util.regex.Matcher; import java.util.regex.Pattern; public class Main { private static final Pattern p = Pattern.compile("[$][{]([^}]+)[}]"); /**/*from w w w . j a v a 2s. c om*/ * Replaces any ${} strings with their corresponding environent variable. * * @param val * @return */ public static String replace(String val) { Matcher matcher = p.matcher(val); StringBuffer buf = new StringBuffer(); while (matcher.find()) { String envVar = matcher.group(1); String envVal = System.getProperty(envVar); if (envVal == null) envVal = "NOT-SPECIFIED"; matcher.appendReplacement(buf, envVal.replace("\\", "\\\\")); } matcher.appendTail(buf); return buf.toString(); } }