[Groovy] 关于String.eachMatch的疑惑

iciness 2012-01-18
最近在学习groovy
在groovy in action一书中关于正则的示例
myFairStringy = 'The rain in Spain stays mainly in the plain!'
BOUNDS = /\b/
rhyme = /$BOUNDS\w*ain$BOUNDS/

found = ''
myFairStringy.eachMatch(rhyme) { match ->
    found += match[0] + ' '
}

assert found == 'rain Spain plain '


事实执行的结果是

assert found == 'r S p '


求解惑
kidli 2012-02-02
rhyme = /$BOUNDS(\w*ain)$BOUNDS/
少了括号。
iciness 2012-02-16
谢谢:)~~~~
Global site tag (gtag.js) - Google Analytics