Matcher: group() : Matcher « java.util.regex « Java by API






Matcher: group()

/*
 * Output:
Match: X
Match: XX
Match: XXX

 * */

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class MainClass {
    public static void main(String args[]) { 
      Pattern pat = Pattern.compile("X+"); 
      Matcher mat = pat.matcher("X XX XXX"); 
   
      while(mat.find()) 
        System.out.println("Match: " + mat.group());  
    } 
}

           
       








Related examples in the same category

1.Matcher: appendReplacement(StringBuffer sb,String replacement)
2.Matcher.appendTail(StringBuffer sb)
3.Matcher: find()
4.Matcher: group(int group)
5.Matcher: groupCount()
6.Matcher: lookingAt()
7.Matcher: matches()
8.Matcher: replaceAll(String text)
9.Matcher: start()