Skip to content

Instantly share code, notes, and snippets.

@jashatton
Created July 30, 2012 17:21
Show Gist options
  • Save jashatton/3208504 to your computer and use it in GitHub Desktop.
Save jashatton/3208504 to your computer and use it in GitHub Desktop.
Hamcrest Regular Expression Matcher.Copied from http://piotrga.wordpress.com/2009/03/27/hamcrest-regex-matcher/
import org.hamcrest.BaseMatcher;
import org.hamcrest.Description;
public class RegexMatcher extends BaseMatcher {
private final String regex;
public RegexMatcher(String regex){
this.regex = regex;
}
public boolean matches(Object o){
return ((String)o).matches(regex);
}
public void describeTo(Description description){
description.appendText("matches regex=");
}
public static RegexMatcher matches(String regex){
return new RegexMatcher(regex);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment