This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Regex SCJP 5.0 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Regex SCJP 5.0" Watch "Regex SCJP 5.0" New topic

Regex SCJP 5.0

Edmen Tay
Ranch Hand

Joined: Oct 21, 2008
Posts: 39
Hi all,

import java.util.regex.*;
public class Regex2 {
public static void main(String[] args){
Pattern p = Pattern.compile("\\d*");
Matcher m = p.matcher("ab34ef");
boolean b = false;
while(b = m.find()){
System.out.print(m.start() +;

Output : 01234456

Question from "SCJP Sun Certified Programmer for Java 5 Study Guide (Exam 310-055) by Kathy SierraandBert Bates" Chapter 6: String, I/O, Formatting, Parsing, Self Test : Question 1.

I don't understand why the index can reaches 6? As I know, m.start() start from 0 then 1,2, matches 34, after that index become 4,5,6 i don't understand. Please help.
Thomas Thevis
Ranch Hand

Joined: Sep 02, 2008
Posts: 87
Hello Edmen,

have a look at this posting from several weeks ago: quantifier.


[ October 23, 2008: Message edited by: Thomas Thevis ]
[ October 23, 2008: Message edited by: Thomas Thevis ]

SCJP 5.0, SCJD in progress
I agree. Here's the link:
subject: Regex SCJP 5.0
It's not a secret anymore!