@Test public void testMatchingComplexRegex(){ String ipAddressPattern = "((2[0-4]\\d|25[0-5]|[01]?\\d\\d?)\\.){3}(2[0-4]\\d|25[0-5]|[01]?\\d\\d?)"; Assert.assertTrue(new RegexMatcher(ipAddressPattern).matching("1.1.1.1")); Assert.assertFalse(new RegexMatcher(ipAddressPattern).matching("255.256.255.0")); Assert.assertFalse(new RegexMatcher(ipAddressPattern).matching("1.1.1")); Assert.assertTrue(new RegexMatcher("^foobar$").matching("foobar")); Assert.assertFalse(new RegexMatcher("^foobar$").matching("\nfoobar")); Assert.assertFalse(new RegexMatcher("^foobar$").matching("foobar\n")); String emailAddressPattern = "[a-z\\d]+(\\.[a-z\\d]+)*@([\\da-z](-[\\da-z])?)+(\\.{1,2}[a-z]+)+"; Assert.assertTrue(new RegexMatcher(emailAddressPattern).matching("foo@bar.com")); Assert.assertFalse(new RegexMatcher(emailAddressPattern).matching("asdfghjkl")); }
@Override public boolean matching(String target) { return null != target && null != pattern && target.matches(pattern); }
RegexMatcher implements Matcher<String> { @Override public boolean matching(String target) { return null != target && null != pattern && target.matches(pattern); } }
RegexMatcher implements Matcher<String> { @Override public boolean matching(String target) { return null != target && null != pattern && target.matches(pattern); } RegexMatcher(String pattern); }
RegexMatcher implements Matcher<String> { @Override public boolean matching(String target) { return null != target && null != pattern && target.matches(pattern); } RegexMatcher(String pattern); @Override boolean matching(String target); }
RegexMatcher implements Matcher<String> { @Override public boolean matching(String target) { return null != target && null != pattern && target.matches(pattern); } RegexMatcher(String pattern); @Override boolean matching(String target);  }