RegexPredicate implements Predicate<CharSequence> { public RegexPredicate(String regex) { this(Pattern.compile(regex)); } RegexPredicate(String regex);  RegexPredicate(Pattern pattern); boolean apply(@Nullable CharSequence input); @Override String toString();  }
@Test public void testRegexPredicate() { RegexPredicate matchAllPredicate = new RegexPredicate(Pattern.compile(".*")); assertTrue(matchAllPredicate.apply("text")); assertTrue(matchAllPredicate.apply("")); assertFalse(matchAllPredicate.apply(null)); matchAllPredicate = new RegexPredicate(".*"); assertTrue(matchAllPredicate.apply("text")); assertTrue(matchAllPredicate.apply("")); assertFalse(matchAllPredicate.apply(null)); RegexPredicate regexPredicate = new RegexPredicate("a+b*"); assertTrue(regexPredicate.apply("a")); assertTrue(regexPredicate.apply("ab")); assertFalse(regexPredicate.apply(null)); assertFalse(regexPredicate.apply("x")); assertFalse(regexPredicate.apply("xab")); assertFalse(regexPredicate.apply("abX")); assertFalse(regexPredicate.apply("XabX")); }