Java J2ME JSP J2EE Servlet Android

Java Dangling meta character, PatternSyntaxException

PatternSyntaxException: Unmatched closing ')',

PatternSyntaxException: Unclosed group near,

PatternSyntaxException: Dangling meta character


 

The cause of the above Exceptions are you're trying to use meta character in Java Pattern processing, like regular expression.

The meta characters in this case are ([{\^-$|]})?*+

So if you want to process a String containing any of the meta characters in regular expression procession using java regex you'll get Exception like above. To process String containing a meta character just use escape character, a fore slash('/') before that character.

Any java method that use java regex also give such errors.

For example

Let's see the code below

String input = "I live in Dhaka(agargaon), Bangladesh";

String arr[] = input.split(")");

This will give the Exception PatternSyntaxException: Unmatched closing ')',

One more such method is indexOf().


 

In this case you have ti change the above code as

String arr[] = input.split("\\)");

Or for indexOf

input.indexOf("\\)");