@Test public void matches_nested_groups() { TreeRegexp tr = new TreeRegexp("^A (\\d+) thick line from ((\\d+),\\s*(\\d+),\\s*(\\d+)) to ((\\d+),\\s*(\\d+),\\s*(\\d+))"); Group g = tr.match("A 5 thick line from 10,20,30 to 40,50,60"); assertEquals("5", g.getChildren().get(0).getValue()); assertEquals("10,20,30", g.getChildren().get(1).getValue()); assertEquals("10", g.getChildren().get(1).getChildren().get(0).getValue()); assertEquals("20", g.getChildren().get(1).getChildren().get(1).getValue()); assertEquals("30", g.getChildren().get(1).getChildren().get(2).getValue()); assertEquals("40,50,60", g.getChildren().get(2).getValue()); assertEquals("40", g.getChildren().get(2).getChildren().get(0).getValue()); assertEquals("50", g.getChildren().get(2).getChildren().get(1).getValue()); assertEquals("60", g.getChildren().get(2).getChildren().get(2).getValue()); }
Group match(CharSequence s) { final Matcher matcher = pattern.matcher(s); if (!matcher.matches()) return null; return groupBuilder.build(matcher, IntStream.rangeClosed(0, matcher.groupCount()).iterator()); }
TreeRegexp { Group match(CharSequence s) { final Matcher matcher = pattern.matcher(s); if (!matcher.matches()) return null; return groupBuilder.build(matcher, IntStream.rangeClosed(0, matcher.groupCount()).iterator()); } }
TreeRegexp { Group match(CharSequence s) { final Matcher matcher = pattern.matcher(s); if (!matcher.matches()) return null; return groupBuilder.build(matcher, IntStream.rangeClosed(0, matcher.groupCount()).iterator()); } TreeRegexp(String regexp);   TreeRegexp(Pattern pattern); }
TreeRegexp { Group match(CharSequence s) { final Matcher matcher = pattern.matcher(s); if (!matcher.matches()) return null; return groupBuilder.build(matcher, IntStream.rangeClosed(0, matcher.groupCount()).iterator()); } TreeRegexp(String regexp);   TreeRegexp(Pattern pattern); GroupBuilder getGroupBuilder(); }
TreeRegexp { Group match(CharSequence s) { final Matcher matcher = pattern.matcher(s); if (!matcher.matches()) return null; return groupBuilder.build(matcher, IntStream.rangeClosed(0, matcher.groupCount()).iterator()); } TreeRegexp(String regexp);   TreeRegexp(Pattern pattern); GroupBuilder getGroupBuilder();  }