File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

'PatternSyntaxException' when attempting to use 'split' with a String

 
Jeremy Watts
Greenhorn
Posts: 19
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have the string, "4563+943", and then when i attempt "4563+943".split("+"), I get the 'PatternSyntaxException' message. What is wrong here?

Thanks
Jeremy
 
Kemal Sokolovic
Bartender
Posts: 825
5
Java Python Ruby
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should escape the '+' character, since it's reserved (has a special meaning) with regular expressions. Try .split("\\+").
 
Jeremy Watts
Greenhorn
Posts: 19
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, yes that worked, thanks. Does the double slash '\\' mean "treat what's coming next as a String" ?
 
Kemal Sokolovic
Bartender
Posts: 825
5
Java Python Ruby
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It means - treat '+' as a regular character, not as regular expression quantifier.
 
Paul Clapham
Sheriff
Pie
Posts: 20185
26
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And it's not a "double slash". It's a single backslash character. It just looks like two characters because of the escaping rules for String literals.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic