This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Regex question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Regex question" Watch "Regex question" New topic
Author

Regex question

Dinesh Tahiliani
Ranch Hand

Joined: Aug 06, 2007
Posts: 486
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());
}
}
}

Answer is --01234456

Can someone expalin me the use of group?


Thanks<br />Dinesh
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

See our SCJP FAQ: Could someone explain the Regex2 class from K&B's Java 5 Study Guide?


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Regex question
 
Similar Threads
Vararg Problem
Variable args and Array
Question on standard action <jsp:useBean
Constructor Calling
Can a class has two main's