A friendly place for programming greenhorns!
Big Moose Saloon
Search
|
Java FAQ
|
Recent Topics
Register / Login
Win a copy of
The Mikado Method
this week in the
Agile and other Processes
forum!
JavaRanch
»
Java Forums
»
Certification
»
Programmer Certification (SCJP/OCPJP)
Author
Regex
Natasha Basu
Greenhorn
Joined: Nov 21, 2008
Posts: 10
posted
Jun 03, 2009 13:19:05
0
This is a question from the certification book by Kathy Sierra Chapter 6
import java.util.regex.*
class Regex2{
public static void main (
String
[] args){
Pattern
p=Pattern.matcher(args[0]);
Matcher m=p.matcher(args[1]);
boolean b=false;
while(b=m.find()){
System.out.println(m.start() + m.group());
}
}
}
And the command line:
java
Regex2 "\d*" ab34ef
and the answer is 01234456
I would like to know how that answer was arrived at?
Ulf Dittmer
Marshal
Joined: Mar 22, 2005
Posts: 35252
7
posted
Jun 03, 2009 13:47:51
0
That's a FAQ:
http://faq.javaranch.com/java/ScjpFaq#kb-regexp
Android apps
–
ImageJ plugins
–
Java web charts
Natasha Basu
Greenhorn
Joined: Nov 21, 2008
Posts: 10
posted
Jun 03, 2009 15:37:23
0
Thank you. I could not understand the digit 6 in the end. Thank you again
I agree. Here's the link:
http://aspose.com/file-tools
subject: Regex
Similar Threads
Doubt about K&B Chapter 6 Question 1
Chapter 6 Self Test Q1
Java command-line input argument??
SCJP question doubt?
Regex doubt
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter