def host = /\/\/([a-zA-Z0-9-]+(\.[a-zA-Z0-9-])*?)(:|\/)/
assertHost 'http://a.b.c.d:8080/bla', host, 'a.b.c.d'
def assertHost (candidate, regex, expected){
candidate.eachMatch(regex){assert it[1] == expected}
}
I know that the above code validates my inputs! But on line 4, inside the closure, the magic variable (it) is represented in the array! I'm a little confused. How it works?
How does it work in Groovy (illustrate with simple code)?
Ant's source
share