Package com.jcabi.matchers
Class RegexMatchers
- java.lang.Object
-
- com.jcabi.matchers.RegexMatchers
-
public final class RegexMatchers extends Object
Convenient matchers for checking Strings against regular expressions.- Since:
- 1.3
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static org.hamcrest.Matcher<String>
containsAllPatterns(String... patterns)
Checks whether aString
contains a subsequence matching any of the given regular expressions.static org.hamcrest.Matcher<String>
containsAnyPattern(String... patterns)
Checks whether aString
contains a subsequence matching any of the given regular expressions.static org.hamcrest.Matcher<String>
containsPattern(String pattern)
Checks whether a String contains a subsequence matching the given regular expression.static org.hamcrest.Matcher<String>
matchesAnyPattern(String... patterns)
Checks whether a String matches at lease one of given regular expressions.static org.hamcrest.Matcher<String>
matchesPattern(String pattern)
Checks whether a String matches the given regular expression.
-
-
-
Method Detail
-
matchesAnyPattern
public static org.hamcrest.Matcher<String> matchesAnyPattern(String... patterns)
Checks whether a String matches at lease one of given regular expressions.- Parameters:
patterns
- Regular expression patterns- Returns:
- Matcher suitable for JUnit/Hamcrest matching
-
matchesPattern
public static org.hamcrest.Matcher<String> matchesPattern(String pattern)
Checks whether a String matches the given regular expression. Works in a similar manner toString.matches(String)
. For example:MatcherAssert.assert( "abc123", RegexMatchers.matchesPattern("[a-c]+\\d{3}") );
- Parameters:
pattern
- The pattern to match against- Returns:
- Matcher suitable for JUnit/Hamcrest matching
-
containsPattern
public static org.hamcrest.Matcher<String> containsPattern(String pattern)
Checks whether a String contains a subsequence matching the given regular expression. Works in a similar manner toMatcher.find()
. For example:MatcherAssert.assert( "fooBar123", RegexMatchers.containsPattern("Bar12") );
- Parameters:
pattern
- The pattern to match against- Returns:
- Matcher suitable for JUnit/Hamcrest matching
-
containsAnyPattern
public static org.hamcrest.Matcher<String> containsAnyPattern(String... patterns)
Checks whether aString
contains a subsequence matching any of the given regular expressions.- Parameters:
patterns
- The patterns to match against- Returns:
- Matcher suitable for JUnit/Hamcrest matching
- See Also:
Matcher.find()
,containsPattern(String)
-
containsAllPatterns
public static org.hamcrest.Matcher<String> containsAllPatterns(String... patterns)
Checks whether aString
contains a subsequence matching any of the given regular expressions.- Parameters:
patterns
- The patterns to match against- Returns:
- Matcher suitable for JUnit/Hamcrest matching
- See Also:
Matcher.find()
,containsPattern(String)
-
-