@Test void findWithoutMatches() { RegexTool tool = new RegexTool(); List<RegexResult> result = tool.find("nothing here", "something"); assertEquals(0, result.size()); }
public List<RegexResult> find(String content, String regex) { List<RegexResult> result = new ArrayList<>(); Matcher matcher = Pattern.compile(regex, Pattern.MULTILINE).matcher(content); if (matcher.find()) { for (int i = 0; i < matcher.groupCount() + 1; i++) { result.add(new RegexResult(matcher.start(i), matcher.end(i), matcher.group(i))); } } return result; }
RegexTool { public List<RegexResult> find(String content, String regex) { List<RegexResult> result = new ArrayList<>(); Matcher matcher = Pattern.compile(regex, Pattern.MULTILINE).matcher(content); if (matcher.find()) { for (int i = 0; i < matcher.groupCount() + 1; i++) { result.add(new RegexResult(matcher.start(i), matcher.end(i), matcher.group(i))); } } return result; } }
RegexTool { public List<RegexResult> find(String content, String regex) { List<RegexResult> result = new ArrayList<>(); Matcher matcher = Pattern.compile(regex, Pattern.MULTILINE).matcher(content); if (matcher.find()) { for (int i = 0; i < matcher.groupCount() + 1; i++) { result.add(new RegexResult(matcher.start(i), matcher.end(i), matcher.group(i))); } } return result; }  }
RegexTool { public List<RegexResult> find(String content, String regex) { List<RegexResult> result = new ArrayList<>(); Matcher matcher = Pattern.compile(regex, Pattern.MULTILINE).matcher(content); if (matcher.find()) { for (int i = 0; i < matcher.groupCount() + 1; i++) { result.add(new RegexResult(matcher.start(i), matcher.end(i), matcher.group(i))); } } 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<RegexResult> find(String content, String regex) { List<RegexResult> result = new ArrayList<>(); Matcher matcher = Pattern.compile(regex, Pattern.MULTILINE).matcher(content); if (matcher.find()) { for (int i = 0; i < matcher.groupCount() + 1; i++) { result.add(new RegexResult(matcher.start(i), matcher.end(i), matcher.group(i))); } } 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);  }