Saturday, 23 January 2016

Getting Error Message : java.util.regex.PatternSyntaxException: Unclosed character class near index 0

While try to split the value by using "[" OR "]" then we are getting the above issue.


Ex : String str="Selenium []"
    str.split("[")

we are getting the below exception.


Exception :

java.util.regex.PatternSyntaxException: Unclosed character class near index 0


Solution

The Special character "["  and "]" used in Regular Experssions, so these characters are not standared characters.

So we should add excape character for use this special character ("\[" and "\]"). But the escape character "\" is not allowed for "["  and "]".

So we should use string as "\\[" or "\\]"


Exact code will be

Ex : String str="Selenium []"
    str.split("\\[")


http://stackoverflow.com/questions/21816788/unclosed-character-class-error

3 comments:

  1. Great blog I must say from every perspective. Thanks for your own hard work on this web page. I love seeing blogs that understand the value of providing a quality resource for free. While clicking games are gaining trend, players shouldn't learn the techniques of spacebar clicking. Use Spacebar Test, and try in-game. you can get information about Spacebar Clicker in the article I shared.

    ReplyDelete
  2. Your positive attitude is like a ray of sunshine on even the cloudiest of days.earth minecraft servers foster collaboration and cooperation, encouraging players to work together towards common goals.

    ReplyDelete
  3. Your respectful demeanor adds immense value to the discussions here.The Lanthony Desaturated 15-hue Color Blind Test
    assesses blue-yellow vision.

    ReplyDelete