• 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
Posts: 42970
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.
 
Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!