wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Regex Program Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Regex Program" Watch "Regex Program" New topic
Author

Regex Program

Srinivas Katta
Ranch Hand

Joined: Feb 01, 2007
Posts: 76
Hi,

I have executed the below Program from K&B

And the command line:
java Regex2 "\d*" ab34ef

My assumption is that the output would be 0123445 but the actual output displayed is 01234456. I do not understand how?

Thanks
Srinivas
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

Check this FAQ.


[My Blog]
All roads lead to JavaRanch
Sahil Kapoor
Ranch Hand

Joined: Sep 12, 2009
Posts: 316
\d* eseentially implies zero or more numeric digits.

Zero length match can occur in several places and one out of it is

After the last character of source data. in your example 6 !!!

See pg 500 in K&B !!!


SCJP 6.0 96%

(Connecting the Dots ....)
 
jQuery in Action, 2nd edition
 
subject: Regex Program
 
Similar Threads
Matcher.find() -> looks one past end of String?
Pattern Matching
regex
doubt regarding patterns in regex
Greedy quantifiers(*)