String keystorePath = "C:/ims/jboss/test/me";
String jbossPath = "C:/ims/jboss";
keystorePath.replaceFirst(jbossPath, "${jboss.server.home.dir}");
In Java 5.0, I get the following error:
Exception in thread "main" java.lang.IllegalArgumentException: Illegal
group reference
at java.util.regex.Matcher.appendReplacement(Matcher.java:706)
at java.util.regex.Matcher.replaceFirst(Matcher.java:848)
at java.lang.String.replaceFirst(String.java:1967)
at TestClass.main(TestClass.java:583)
Help?
Almost, not quite. '$' is a special character in the *replacement
string*. 'Each occurrence of $g will be replaced by the result of
evaluating group(g)'. See
http://java.sun.com/j2se/1.5.0/docs/api/java/util/regex/Matcher.html#appendReplacement(java.lang.StringBuffer,%20java.lang.String)
> You should escape it with
> '\\'.
You should escape it as '\$'.