Groovy语言---正则表达式三(捕获组)

def goods =
        """computer 3000¥ 10%
mouse 50¥ 0%
memory 200¥ 20%"""
def groups = {
    def re = /(.*) (.*)¥ (.*)%/
    def matcher = (it =~ re)
    println matcher.class
//    println matcher[0]
//    println matcher[1]
//    println matcher[2]
    matcher.each {
        println it
    }
}
goods.split('/n').each(groups)
运行结果的截图为:
Groovy语言---正则表达式三(捕获组)_第1张图片

你可能感兴趣的:(Regex正则表达式,Groovy)