String.replaceFirst - Illegal group reference

O

O.B.

In Java 1.4, the following works fine:

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?
 
H

hiwa

O.B. said:
In Java 1.4, the following works fine:

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?
'$' is a special character for Java regex. You should escape it with
'\\'.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top