 |
Subscribe to this site |
|
Test !=~
// match 'somedata', followed by 0-N instances of ':somedata'...
String regex = /^somedata(:somedata)*$/
// assert matches...
assert "somedata" ==~ regex
assert "somedata:somedata" ==~ regex
assert "somedata:somedata:somedata" ==~ regex
// assert not matches...
try {
assert !("somedata:somedata:somedata" ==~ regex)
throw new RuntimeException("Won't get here")
} catch (AssertionError ae) {
// Expect to get here
}
try {
assert "somedata:somedata:somedata" !=~ regex
throw new RuntimeException("Do get here because !=~ doesn't negate the match")
} catch (AssertionError ae) {
// Won't get here
}