aspose file tools*
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
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
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Regex question