Java tutorial
/* * 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()); } }