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

String.split() method and Regex question from Whizlabs

 
Ida Achi
Greenhorn
Posts: 26
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Please assist me understand why the following code prints 4 and not 3? Thanks



 
Anshul Agrawal
Greenhorn
Posts: 19
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The String.split() method splits a string around matches of the given regular expression. The return value is a String array containing the tokens.

In this case we split on the expression "a{3}" and the tokens are stored in the array s. Here, the regular expression a{3} is searching for three occurrences of the letter "a" in a row. ...

To match a pattern exactly n number of times, we specify the number inside a set of braces.
it will have 3 blank strings and one "bb"


 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic