This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Regex Question from K&B book Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Regex Question from K&B book" Watch "Regex Question from K&B book" New topic
Author

Regex Question from K&B book

salil kulkarni
Greenhorn

Joined: Sep 18, 2007
Posts: 3
Hi,

I found this question at:
http://www.wickedlysmart.com/SCJPStudyGuide/Java_5_SCJPquestions.html

and it says:

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

What is the result?

The answer is: E). 01234456

As per my understanding, I am still confused as to how the '6' is derived in the above answer?

It would be great if someone can explain.

Thanks,
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42374
    
  64
Welcome to JavaRanch.

That questions gets asked so frequently that it has its own entry in the FAQ: http://faq.javaranch.com/java/ScjpFaq#kb-regexp


Ping & DNS - my free Android networking tools app
salil kulkarni
Greenhorn

Joined: Sep 18, 2007
Posts: 3
Thanks Ulf, the answer just confirmed what I was suspecting but not sure about.
That explains it.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Regex Question from K&B book