File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Regex Program" Watch "Regex Program" New topic

Regex Program

Srinivas Katta
Ranch Hand

Joined: Feb 01, 2007
Posts: 75

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?

Christophe Verré

Joined: Nov 24, 2005
Posts: 14687

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 ....)
I agree. Here's the link:
subject: Regex Program
Similar Threads
Greedy quantifiers(*)
doubt regarding patterns in regex
Matcher.find() -> looks one past end of String?
Pattern Matching