Question 148 / 297:  Given the following code, what is the expected output?
import java.util.regex.Matcher;

import java.util.regex.Pattern;

public class Tester {

public static void main(String[] args) {

Pattern p = Pattern.compile("[a-f]\\d+");

Matcher m = p.matcher("ab34ef0");

while(m.find()) {

System.out.print(m.start()+" "+m.group());

}

}

}

A  0 ab345 f0
B  0 ab344 ef0
C  1 b35 f0
D  1 b345 f0
<< First < Previous Next > Last >>
Explanation:

We are looking for a match of not least and not more than one occurrence of a letter between 'a' to 'f' and followed by at least one occurrence of a digit

start() returns the index of the matched literal

group() returns the matched literal

Exam Home Page
Ask
Stephanie Redfern
Start Quiz
Kimberly Nichols
Start Test
Copy and paste the following HTML code into your website or blog.
<iframe src="https://www.jobilize.com/embed/java-certification-questions" width="600" height="600" frameborder="0" marginwidth="0" marginheight="0" scrolling="yes" style="border:1px solid #CCC; border-width:1px 1px 0; margin-bottom:5px" allowfullscreen webkitallowfullscreen mozallowfullscreen> </iframe>