Pattern pathPattern = Pattern.compile("\\$\\{(.+?)\\}");
Matcher matcherPattern = pathPattern.matcher(input); // get a matcher
// object
StringBuffer sb = new StringBuffer();
EnvironmentConfiguration config = new EnvironmentConfiguration();
SystemConfiguration sysConfig = new SystemConfiguration();
while (matcherPattern.find())
{
String confVarName = matcherPattern.group(1) != null ? matcherPattern.group(1) : matcherPattern.group(2);
String envConfVarValue = config.getString(confVarName);
String sysVarValue = sysConfig.getString(confVarName);
if (envConfVarValue != null)
{
matcherPattern.appendReplacement(sb, envConfVarValue);