package org.hamcrest.text;

import java.util.regex.Pattern;

import org.hamcrest.Description;
import org.hamcrest.Factory;
import org.hamcrest.Matcher;
import org.hamcrest.TypeSafeMatcher;

public class MatchesPattern extends TypeSafeMatcher<String> {
    private final Pattern pattern;

    public MatchesPattern(Pattern pattern) {
        this.pattern = pattern;
    }

    @Override
    protected boolean matchesSafely(String item) {
        return pattern.matcher(item).matches();
    }

    @Override
    public void describeTo(Description description) {
        description.appendText("a string matching the pattern '" + pattern + "'");
    }

    @Factory
    public static Matcher<String> matchesPattern(Pattern pattern) {
        return new MatchesPattern(pattern);
    }

    @Factory
    public static Matcher<String> matchesPattern(String regex) {
        return new MatchesPattern(Pattern.compile(regex));
    }
}

@@ -651,135 +651,462 @@
     
-@Factory%0A    public static Matcher%3CString%3E matchesPattern(Pattern pattern) %7B%0A        return new MatchesPattern(pattern);%0A    %7D%0A
+/**%0A     * Creates a matcher of %7B@link String%7D that matches when the examined string%0A     * exactly matches the given %7B@link Pattern%7D.%0A     */%0A    @Factory%0A    public static Matcher%3CString%3E matchesPattern(Pattern pattern) %7B%0A        return new MatchesPattern(pattern);%0A    %7D%0A%0A    /**%0A     * Creates a matcher of %7B@link String%7D that matches when the examined string%0A     * exactly matches the given regular expression, treated as a %7B@link Pattern%7D.%0A     */
 %0A   

Add Javadoc for factory methods.