Two Laptop Bag
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Regex Question from SCJP (Sierra & Bates) 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 Question from SCJP (Sierra & Bates)" Watch "Regex Question from SCJP (Sierra & Bates)" New topic

Regex Question from SCJP (Sierra & Bates)

Khalid Chowdhury

Joined: Jun 03, 2008
Posts: 2

And the command line:

I'm confused as to why the output is 01234456

I'd be really grateful is someone could explain this.
Konrad Till

Joined: Nov 20, 2012
Posts: 7
There is "234" in the output, because "34" match has been found at index 2.
Rest are indexes of zero-length matches, because * means zero or more.
See also exam watch on page 500 in the K&B book.
Henry Wong

Joined: Sep 28, 2004
Posts: 20535

Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
I agree. Here's the link:
subject: Regex Question from SCJP (Sierra & Bates)
It's not a secret anymore!