@Test public void testMatchingWithRegularGrammar(){ Assert.assertTrue(new RegexMatcher("foo?").matching("fo")); Assert.assertTrue(new RegexMatcher("foo?").matching("foo")); Assert.assertTrue(new RegexMatcher("foo.").matching("fooo")); Assert.assertTrue(new RegexMatcher("foo*").matching("fooooo")); Assert.assertTrue(new RegexMatcher("foo.*").matching("foobarbarbar")); Assert.assertFalse(new RegexMatcher("foo+").matching("fo")); Assert.assertTrue(new RegexMatcher("foo+").matching("fooooo")); Assert.assertTrue(new RegexMatcher("foo\\s").matching("foo ")); Assert.assertFalse(new RegexMatcher("foo\\S").matching("foo ")); Assert.assertTrue(new RegexMatcher("foo\\w").matching("fooo")); Assert.assertTrue(new RegexMatcher("foo\\W").matching("foo ")); Assert.assertFalse(new RegexMatcher("foo\\W").matching("fooo")); Assert.assertTrue(new RegexMatcher("foo[1234]").matching("foo1")); Assert.assertFalse(new RegexMatcher("foo[1234]").matching("foo5")); Assert.assertTrue(new RegexMatcher("foo\\\\").matching("foo\\")); Assert.assertTrue(new RegexMatcher("foo\\d").matching("foo5")); Assert.assertTrue(new RegexMatcher("fo{1,3}").matching("fo")); Assert.assertFalse(new RegexMatcher("fo{1,3}").matching("foooo")); }
@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);  }