Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Doubt in split().

 
Amit Batra
Ranch Hand
Posts: 361
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


The above is a question from whizlab simulator. Can anyone please tell me how the output is coming to be 4?
I thought the split method is supposed to split a string around matches of a regex. here regex is a{3} so doesnt that leave bb to be the two tokens.??
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The tokens are "", "", "", "bb" as shown below:

[ August 13, 2006: Message edited by: Barry Gaunt ]
 
Amit Batra
Ranch Hand
Posts: 361
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
BUt how can a string of zero length be considered a token when I havent used any kind of greedy quantifier? And going by the explanation. there is a token on the left of the first ""aaa. Then why isnt there also a token just before the BB. like aaa""bb".?
I hate regexing
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The "bb" is the token. Just before this token there is the separator "aaa".
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic