@Override public boolean matches(String str) { return matcher.matches(str); }
@Override public boolean matches(String str) { return matcher.matches(str); }
@Override public boolean matches(Map<String, String> tags) { String s = tags.get(k); return s != null && pattern.matches(s); }
/** * Helper function to check if a string value matches the provided pattern. Note, if matching * many values against the same pattern, then it is much more efficient to use * {@link #compile(String)} to get an instance of a matcher that can be reused. * * @param pattern * Pattern to use for creating the matcher instance. * @param value * Value to check against the pattern. * @return * True if the pattern matches the value. */ static boolean matches(String pattern, String value) { return compile(pattern).matches(value); } }
/** * Helper function to check if a string value matches the provided pattern. Note, if matching * many values against the same pattern, then it is much more efficient to use * {@link #compile(String)} to get an instance of a matcher that can be reused. * * @param pattern * Pattern to use for creating the matcher instance. * @param value * Value to check against the pattern. * @return * True if the pattern matches the value. */ static boolean matches(String pattern, String value) { return compile(pattern).matches(value); } }
@Override protected void testRE(String regex, String value) { Pattern pattern = Pattern.compile("^.*(" + regex + ")", Pattern.DOTALL); PatternMatcher matcher = PatternMatcher.compile(regex); if (pattern.matcher(value).find()) { Assertions.assertTrue(matcher.matches(value), regex + " should match " + value); } else { Assertions.assertFalse(matcher.matches(value), regex + " shouldn't match " + value); } // Check pattern can be recreated from toString PatternMatcher actual = PatternMatcher.compile(matcher.toString()); Assertions.assertEquals(matcher, actual); } }
@Override protected void testRE(String regex, String value) { // Java regex has inconsistent behavior for POSIX character classes and the literal version // of the same character class. For now we skip regex that use POSIX classes. // https://bugs.openjdk.java.net/browse/JDK-8214245 if (!regex.contains("\\p{") && !regex.contains("\\P{") && !regex.contains("[^")) { int flags = Pattern.DOTALL | Pattern.CASE_INSENSITIVE; Pattern pattern = Pattern.compile("^.*(" + regex + ")", flags); PatternMatcher matcher = PatternMatcher.compile(regex).ignoreCase(); if (pattern.matcher(value).find()) { Assertions.assertTrue(matcher.matches(value), regex + " should match " + value); } else { Assertions.assertFalse(matcher.matches(value), regex + " shouldn't match " + value); } // Check pattern can be recreated from toString PatternMatcher actual = PatternMatcher.compile(matcher.toString()); Assertions.assertEquals(matcher, actual); } } }