Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

PatternSyntaxException: Unclosed character class near index

800474Mar 24 2008 — edited Mar 24 2008
Hi,

I want to replace in a string a expression like "^1:2" by "^(1/2)":
For example, "V/Hz^1:2" would be converted to "V/Hz^(1/2)".

I tried the following code:
String oldExponent = "[^](\\d+):(\\d+)"; // e.g. ^1:2
String newExponent = "^($1/$2)";         // e.g. ^(1/2)
myString = myString.replaceAll(oldExponent, newExponent);
but the following exception is thrown in the third line:
java.util.regex.PatternSyntaxException: Unclosed character class near index 13
[^](\d+):(\d+)
             ^
Any idea?

Thanks in advance.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 21 2008
Added on Mar 24 2008
2 comments
2,958 views