mirror of
https://github.com/corda/corda.git
synced 2025-01-04 04:04:27 +00:00
27 lines
683 B
Java
27 lines
683 B
Java
|
import regex.Matcher;
|
||
|
import regex.Pattern;
|
||
|
|
||
|
public class Regex {
|
||
|
private static void expect(boolean v) {
|
||
|
if (! v) throw new RuntimeException();
|
||
|
}
|
||
|
|
||
|
private static Matcher getMatcher(String regex, String string) {
|
||
|
return Pattern.compile(regex).matcher(string);
|
||
|
}
|
||
|
|
||
|
private static void expectMatch(String regex, String string) {
|
||
|
expect(getMatcher(regex, string).matches());
|
||
|
}
|
||
|
|
||
|
private static void expectNoMatch(String regex, String string) {
|
||
|
expect(!getMatcher(regex, string).matches());
|
||
|
}
|
||
|
|
||
|
public static void main(String[] args) {
|
||
|
expectMatch("a(bb)?a", "abba");
|
||
|
expectNoMatch("a(bb)?a", "abbba");
|
||
|
expectNoMatch("a(bb)?a", "abbaa");
|
||
|
}
|
||
|
}
|