File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Regex SCJP 5.0" Watch "Regex SCJP 5.0" New topic
Author

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() + m.group());
}

}
}
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.

Regards,
Thomas

[ 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: http://aspose.com/file-tools
 
subject: Regex SCJP 5.0