aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Scanner not scanning for a regular expression Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Scanner not scanning for a regular expression" Watch "Scanner not scanning for a regular expression" New topic
Author

Scanner not scanning for a regular expression

Sanjeev Singh
Ranch Hand

Joined: Nov 01, 2006
Posts: 381
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?


~Sanjeev Singh<br />SCJP 1.5
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42280
    
  64
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.


Ping & DNS - my free Android networking tools app
 
 
subject: Scanner not scanning for a regular expression