Groovy2.0で追加されたMatcher#matchesPartially

元ネタ http://mrhaki.blogspot.fr/2012/06/groovy-goodness-partial-matches.html

APIはこのへん。
http://groovy.codehaus.org/groovy-jdk/java/util/regex/Matcher.html#matchesPartially()

なかなか説明が難しいのですが、とある文字列があって、その文字列に続く文字によってマッチする可能性があるものをtrueとして扱い、もうその文字列に続く文字がなんでもあってもマッチする可能性がないというものをfalseとして扱うという感じでしょう。

def regex = /(090|080)-\d{4}-\d{4}/

def matcher = '090-1234-5678' =~ regex
assert matcher.matchesPartially()

matcher = '080-0987-6543' =~ regex
assert matcher.matchesPartially() 

matcher = '090-09' =~ regex
assert matcher.matchesPartially()

matcher = '0' =~ regex
assert matcher.matchesPartially()

matcher = '07' =~ regex
assert matcher.matchesPartially() == false

matcher = '090-98765' =~ regex
assert matcher.matchesPartially() == false