### Question:
RegexTools { public static List<Tuple3<Integer, Integer, String>> findAll(Pattern pattern, String text, boolean matchGroups) { if (StringUtils.isEmpty(text)) return Collections.emptyList(); Matcher matcher = pattern.matcher(text); List<Tuple3<Integer, Integer, String>> r= Lists.newArrayList(); while (matcher.find()) { int groupCount = matcher.groupCount(); if (groupCount==0 || !matchGroups) { r.add(getMatch(matcher, 0)); } else { for (int i=1; i<=groupCount; i++) { r.add(getMatch(matcher, i)); } } } return r; }  static List<Tuple3<Integer, Integer, String>> findAll(Pattern pattern, String text, boolean matchGroups); static List<Tuple3<Integer, Integer, String>> findAll(String pattern, String text, boolean matchGroups, RegexFlagsEnum... flags);  }### Answer:
@Test public void testFindAll() { String pattern= "A+"; String text= "A-AA-AAA-"; List<Tuple3<Integer, Integer, String>> found = RegexTools.findAll(pattern, text, true); assertEquals(3, found.size()); List<Tuple3<Integer, Integer, String>> expected= ImmutableList.of( Tuple3.tuple3(0, 1, "A"), Tuple3.tuple3(2, 4, "AA"), Tuple3.tuple3(5, 8, "AAA") ); assertEquals(expected, found); }
@Test public void testFindAllWithGroups() { String pattern= "\\bhref\\b\\s*=\\s*(\\S*?)[\\s>]"; String text= "<A href= a.c at >t</a>"; List<Tuple3<Integer, Integer, String>> found = RegexTools.findAll(pattern, text, true); assertEquals(1, found.size()); List<Tuple3<Integer, Integer, String>> expected= ImmutableList.of( Tuple3.tuple3(9, 12, "a.c") ); assertEquals(expected, found); }