File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Scanner not scanning for a regular expression

 
Sanjeev Singh
Ranch Hand
Posts: 381
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was trying to execute the following program for seaching a pattern in the string.

I was expecting the answer as a
tokenfound :
tokenfound :
tokenfound :45
tokenfound :
tokenfound :
tokenfound :

but it is looping infinitely?
 
Ulf Dittmer
Rancher
Pie
Posts: 42966
73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think the problem is that the pattern can be matched by the empty string (which has length 0). If the scanner advances by 0 characters, it will never get beyond the start of the string, and thus finds the same (empty) string over and over.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic