Package com.jcabi.matchers
Class RegexMatchers
java.lang.Object
com.jcabi.matchers.RegexMatchers
Convenient matchers for checking Strings against regular expressions.
- Since:
- 1.3
-
Method Summary
Modifier and TypeMethodDescriptionstatic 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 Details
-
matchesAnyPattern
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
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
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
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:
-
containsAllPatterns
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:
-