1. Given:

And the command line:

java Regex2 "\d*" ab34ef

What is the result?

A. 234

B. 334

C. 2334

D. 0123456

E. 01234456

F. 12334567

G. Compilation fails.

Answer:

® 3 E is correct. The \d is looking for digits. The * is a quantifier that looks for 0 to many

occurrences of the pattern that precedes it. Because we specified *, the group() method

returns empty Strings until consecutive digits are found, so the only time group() returns

a value is when it returns 34 when the matcher finds digits starting in position 2. The

start() method returns the starting position of the previous match because, again,

we said find 0 to many occurrences.

®˚ A, B, C, D, E, F, and G are incorrect based on the above.

(Objective 3.5)

QUESTION: The indexes in the pattern.matcher() string vary from 0 to 5.

ab34ef

012345

How can the answer be E. 01234456 ?

Shouldn't the answer be the following: 0123445 ?