Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Scanner not scanning for a regular expression

 
Sanjeev Singh
Ranch Hand
Posts: 381
  • 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: 42967
73
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic