aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Doubt about K&B Chapter 6 Question 1 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 "Doubt about K&B Chapter 6 Question 1" Watch "Doubt about K&B Chapter 6 Question 1" New topic
Author

Doubt about K&B Chapter 6 Question 1

Justen Hill
Greenhorn

Joined: Nov 07, 2007
Posts: 5
import java.util.regex.*;
class Regex2 {
public static void main(String[] args) {
Pattern p = Pattern.compile(args[0]);
Matcher m = p.matcher(args[1]);
boolean b = false;
while(b = m.find()) {
System.out.print(m.start() + m.group());
}
}
}
And the command line:
java Regex2 "\d*" ab34ef

The answer is 01234456

I understand that the * allows it to list all since zero counts but where I am confused is the last 6 in the answer. There are only 012345 indexes in the provided expression?? How does this index get included?
ahmed yehia
Ranch Hand

Joined: Apr 22, 2006
Posts: 424
Answer to this question is explained here:

http://faq.javaranch.com/java/ScjpFaq#kb-regexp
Justen Hill
Greenhorn

Joined: Nov 07, 2007
Posts: 5
Thanks !!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Doubt about K&B Chapter 6 Question 1