Hi.
I'm trying to match ANT style properties in strings, manually replacing them with something useful in my Java project. The strings come in as;
${some.property}/path2/path3/${other.property}/path5
and I wish to replace all occurences of ${...} with values fetched from a database. I'm a newbie in regexp, but I've tried the following:
String searchFor = "${"+property+"}";
String value = path.replaceAll(searchFor, propValue);
This yields a java.util.regex.PatternSyntaxException: Illegal repetition near index 1
\${scm.root}
I've found the following to work, though:
JSONObject property = props.getJSONObject(j);
String searchFor = "${"+property.getString("NAME")+"}";
while (p.indexOf(searchFor) > -1) {
p = p.substring(0,p.indexOf(searchFor)) + property.getString("PROPERTY_VALUE") + p.substring(p.indexOf(searchFor) + searchFor.length(), p.length());
}
But it would be so much more sexy to use regexp instead.
Any suggestions would be greatly appreciated. Thank you!