Regex { public static Split split(String regex) { return split(Pattern.compile(regex), false); } private  Regex(); static Matches matches(String regex); static Matches matches(Pattern pattern); static Matches matches(String regex, int group); static Matches matches(Pattern pattern, int group); static MatchesName matches(String regex, String groupName); static MatchesName matches(Pattern pattern, String groupName); static AllMatches allMatches(String regex); static AllMatches allMatches(Pattern pattern); static MatchesKV matchesKV(String regex, int keyGroup, int valueGroup); static MatchesKV matchesKV(Pattern pattern, int keyGroup, int valueGroup); static MatchesNameKV matchesKV(String regex, String keyGroupName, String valueGroupName); static MatchesNameKV matchesKV(
      Pattern pattern, String keyGroupName, String valueGroupName); static Find find(String regex); static Find find(Pattern pattern); static Find find(String regex, int group); static Find find(Pattern pattern, int group); static FindName find(String regex, String groupName); static FindName find(Pattern pattern, String groupName); static FindAll findAll(String regex); static FindAll findAll(Pattern pattern); static FindKV findKV(String regex, int keyGroup, int valueGroup); static FindKV findKV(Pattern pattern, int keyGroup, int valueGroup); static FindNameKV findKV(String regex, String keyGroupName, String valueGroupName); static FindNameKV findKV(Pattern pattern, String keyGroupName, String valueGroupName); static ReplaceAll replaceAll(String regex, String replacement); static ReplaceAll replaceAll(Pattern pattern, String replacement); static ReplaceFirst replaceFirst(String regex, String replacement); static ReplaceFirst replaceFirst(Pattern pattern, String replacement); static Split split(String regex); static Split split(Pattern pattern); static Split split(String regex, boolean outputEmpty); static Split split(Pattern pattern, boolean outputEmpty);  }
@Test @Category(NeedsRunner.class) public void testSplits() { PCollection<String> output = p.apply(Create.of("The quick brown fox jumps over the lazy dog")) .apply(Regex.split("\\W+")); PAssert.that(output) .containsInAnyOrder("The", "quick", "brown", "fox", "jumps", "over", "the", "lazy", "dog"); p.run(); }
@Test @Category(NeedsRunner.class) public void testSplitsWithEmpty() { PCollection<String> output = p.apply(Create.of("The quick brown fox jumps over the lazy dog")) .apply(Regex.split("\\s", true)); PAssert.that(output) .containsInAnyOrder( "The", "", "quick", "brown", "", "", "fox", "jumps", "over", "", "", "", "the", "lazy", "dog"); p.run(); }
@Test @Category(NeedsRunner.class) public void testSplitsWithoutEmpty() { PCollection<String> output = p.apply(Create.of("The quick brown fox jumps over the lazy dog")) .apply(Regex.split("\\s", false)); PAssert.that(output) .containsInAnyOrder("The", "quick", "brown", "fox", "jumps", "over", "the", "lazy", "dog"); p.run(); }