Top Fields Constructors Methods
org.hamcrest.core

public Class StringRegularExpression

extends TypeSafeDiagnosingMatcher<String>
Class Inheritance
Imports
java.util.regex.Pattern, org.hamcrest.Description, .Matcher, .TypeSafeDiagnosingMatcher

Authors
borettim, sf105

Field Summary

Modifier and TypeField and Description
private Pattern

Constructor Summary

AccessConstructor and Description
protected

Method Summary

Modifier and TypeMethod and Description
public void
describeTo(Description
The description to be built or appended to.
description
)

Implements org.hamcrest.SelfDescribing.describeTo.

Generates a description of the object.
public static Matcher<String>

Returns:

The matcher.
matchesRegex
(Pattern
the pattern to be used.
pattern
)

Creates a matcher that checks if the examined string matches a specified java.util.regex.Pattern.

public static Matcher<String>

Returns:

The matcher.
matchesRegex
(String
The regex to be used for the validation.
regex
)

Creates a matcher that checks if the examined string matches a specified regex.

protected boolean
matchesSafely(String actual, Description mismatchDescription)

Implements abstract org.hamcrest.TypeSafeDiagnosingMatcher.matchesSafely.

Subclasses should implement this.
Inherited from org.hamcrest.TypeSafeDiagnosingMatcher:
describeMismatchmatches

Field Detail

patternback to summary
private Pattern pattern

Constructor Detail

StringRegularExpressionback to summary
protected StringRegularExpression(Pattern pattern)

Method Detail

describeToback to summary
public void describeTo(Description description)

Implements org.hamcrest.SelfDescribing.describeTo.

Doc from org.hamcrest.SelfDescribing.describeTo.

Generates a description of the object. The description may be part of a a description of a larger object of which this is just a component, so it should be worded appropriately.

Parameters
description:Description

The description to be built or appended to.

Annotations
@Override
matchesRegexback to summary
public static Matcher<String> matchesRegex(Pattern pattern)

Creates a matcher that checks if the examined string matches a specified java.util.regex.Pattern.

assertThat("abc", matchesRegex(Pattern.compile("ˆ[a-z]$"));
Parameters
pattern:Pattern

the pattern to be used.

Returns:Matcher<String>

The matcher.

matchesRegexback to summary
public static Matcher<String> matchesRegex(String regex)

Creates a matcher that checks if the examined string matches a specified regex.

assertThat("abc", matchesRegex("ˆ[a-z]+$"));
Parameters
regex:String

The regex to be used for the validation.

Returns:Matcher<String>

The matcher.

matchesSafelyback to summary
protected boolean matchesSafely(String actual, Description mismatchDescription)

Implements abstract org.hamcrest.TypeSafeDiagnosingMatcher.matchesSafely.

Doc from org.hamcrest.TypeSafeDiagnosingMatcher.matchesSafely.

Subclasses should implement this. The item will already have been checked for the specific type and will never be null.

Annotations
@Override