• Post Reply Bookmark Topic Watch Topic
  • New Topic

java.util.regex.PatternSyntaxException  RSS feed

 
Paul Horner
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello guys and girls,
I want to split a String into a string array with this command:


This error comes:Exception in thread "AWT-EventQueue-0" java.util.regex.PatternSyntaxException: Dangling meta character '+' near index 0
+
so I tested before

but the error is the same. What means this error?
lg Paul
 
Paweł Baczyński
Bartender
Posts: 2085
44
Firefox Browser IntelliJ IDE Java Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch!

Please, UseCodeTags (← this is a link) when posting. I have added them for you this time.

String.split() method takes a regular expression as an argument. Character + has a special meaning in regular expressions.
You need to escape it. So your code shoud be:
 
Kendall Ponder
Ranch Hand
Posts: 205
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The following also works, but there may be a reason not to do it this way I don't know about.
 
Stephan van Hulst
Saloon Keeper
Posts: 7992
143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Depending on the stance of the sun and the moon and the planets, I like to use either approach
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!