List<MatchResult> results = new ArrayList<MatchResult>(); Matcher m = pattern.matcher(text); while(m.find()) results.add(m.toMatchResult()); return results;
Pattern pattern = Pattern.compile(args[0]); String text = args[1]; List<MatchResult> results = findAll(pattern, text); for(MatchResult r : results) { System.out.printf("Found '%s' at (%d,%d)%n", r.group(), r.start(), r.end()); }