private static final Pattern VARIABLE = Pattern.compile("[$][{]([a-zA-Z0-9_/]+)[}]"); public String expand(String s) { String s2 = s; String v = null; Matcher m = VARIABLE.matcher(s); while( m.find() ) { String name = m.group(1); String[] ss = name.split("/"); switch( ss.length) { case 2: v = getValue(ss[0],ss[1]); break; case 1: v = getValue(ss[0]); break; default: v = name; } s2 = m.replaceFirst(v); m = VARIABLE.matcher(s2); } return s2; } public String getValue(String optionName) { return "value of "+optionName; } public String getValue(String sectionName, String optionName) { return "value of "+sectionName+":"+optionName; }