I’m using
str.replaceAll("GeoData[", "");
to replace “[” symbol in some strings in my text file, but I get:
Exception in thread "main" java.util.regex.PatternSyntaxException: Unclosed character class near index 7
GeoData[
^
at java.util.regex.Pattern.error(Pattern.java:1713)
how can I solve this ?
The method
replaceAllinterprets the argument as a regular expression. In a regular expression you must escape[if you want its literal meaning otherwise it is interpreted as the start of a character class.If you didn’t intend to use a regular expression then use
replaceinstead, as Bozho mentions in his answer.