java.util.regex.PatternSyntaxException: Unclosed character class

Exception in thread "main" java.util.regex.PatternSyntaxException:
Unclosed character class near index 1 $[ ^ at java.util.regex.Pattern.error (Pattern.java:1503) at
java.util.regex.Pattern.clazz(Pattern.java:2016) at java.util.regex.Pattern.sequence(Pattern.java:1560)
at java.util.regex.Pattern.expr(Pattern.java:1520) at java.util.regex.Pattern.compile (Pattern.java:1288)
at java.util.regex.Pattern.<init>(Pattern.java:1044)  encountered while splitting the string
using a delimiter which contains "["

Comments

One Response to “java.util.regex.PatternSyntaxException: Unclosed character class”

  1. Expert on January 24th, 2010 1:13 pm

    This error can be encountered while splitting a string or using string.replaceAll(”string which contains a special character”,”x”)
    Following are the special characters in java regular expressions. If you have any one of them in your input string, then you will face this exception.
    Use the common methodology of backslash to escape such characters.

Leave a Reply




Related Post

String.intern in Java
What is an abstract class?
Static in java
What is singleton pattern? Write an example singleton class?
Debugging vicious java.net.BindException (Windows)
Technology