Friday, July 23, 2010

Java String Pattern Matching And Getting Group Of Match Token

 Pattern pat = Pattern.compile("JAVA");
 Matcher mat = pat.matcher("concept JAVA concept");
 while (mat.find()) {
        String token = mat.group();
         System.out.println(token);
 }


"JAVA" is any string which can also accept wildcard character. mat.find(); will return whether the matching string found or not, mat.group(); will return matching token.

No comments:

Post a Comment