@Test void findAll() { RegexTool tool = new RegexTool(); List<List<RegexResult>> result = tool.findAll("one :two three (:four) five :six seven=:eight", ":(\\w+) (\\w+)"); assertEquals(2, result.size()); assertEquals(":two three", result.get(0).get(0).getGroup()); assertEquals(":six seven", result.get(1).get(0).getGroup()); assertEquals(3, result.get(0).size()); assertEquals("two", result.get(0).get(1).getGroup()); assertEquals("three", result.get(0).get(2).getGroup()); assertEquals(3, result.get(1).size()); assertEquals("six", result.get(1).get(1).getGroup()); assertEquals("seven", result.get(1).get(2).getGroup()); }
public List<List<RegexResult>> findAll(String content, String regex) { List<List<RegexResult>> result = new ArrayList<>(); Matcher matcher = Pattern.compile(regex, Pattern.MULTILINE).matcher(content); while (matcher.find()) { List<RegexResult> match = new ArrayList<>(); for (int i = 0; i < matcher.groupCount() + 1; i++) { match.add(new RegexResult(matcher.start(i), matcher.end(i), matcher.group(i))); } result.add(match); } return result; }
RegexTool { public List<List<RegexResult>> findAll(String content, String regex) { List<List<RegexResult>> result = new ArrayList<>(); Matcher matcher = Pattern.compile(regex, Pattern.MULTILINE).matcher(content); while (matcher.find()) { List<RegexResult> match = new ArrayList<>(); for (int i = 0; i < matcher.groupCount() + 1; i++) { match.add(new RegexResult(matcher.start(i), matcher.end(i), matcher.group(i))); } result.add(match); } return result; } }
RegexTool { public List<List<RegexResult>> findAll(String content, String regex) { List<List<RegexResult>> result = new ArrayList<>(); Matcher matcher = Pattern.compile(regex, Pattern.MULTILINE).matcher(content); while (matcher.find()) { List<RegexResult> match = new ArrayList<>(); for (int i = 0; i < matcher.groupCount() + 1; i++) { match.add(new RegexResult(matcher.start(i), matcher.end(i), matcher.group(i))); } result.add(match); } return result; }  }
RegexTool { public List<List<RegexResult>> findAll(String content, String regex) { List<List<RegexResult>> result = new ArrayList<>(); Matcher matcher = Pattern.compile(regex, Pattern.MULTILINE).matcher(content); while (matcher.find()) { List<RegexResult> match = new ArrayList<>(); for (int i = 0; i < matcher.groupCount() + 1; i++) { match.add(new RegexResult(matcher.start(i), matcher.end(i), matcher.group(i))); } result.add(match); } return result; }  List<RegexResult> find(String content, String regex); List<List<RegexResult>> findAll(String content, String regex); Pattern compile(String regex); String quote(String s); String quoteReplacement(String s); }
RegexTool { public List<List<RegexResult>> findAll(String content, String regex) { List<List<RegexResult>> result = new ArrayList<>(); Matcher matcher = Pattern.compile(regex, Pattern.MULTILINE).matcher(content); while (matcher.find()) { List<RegexResult> match = new ArrayList<>(); for (int i = 0; i < matcher.groupCount() + 1; i++) { match.add(new RegexResult(matcher.start(i), matcher.end(i), matcher.group(i))); } result.add(match); } return result; }  List<RegexResult> find(String content, String regex); List<List<RegexResult>> findAll(String content, String regex); Pattern compile(String regex); String quote(String s); String quoteReplacement(String s);  }