Something like:
def match = "John 19" =~ /(&name&)\w+ (&age&\d+)/
def name = match.name
def age = match.age
Is there a groovy syntax that allows for something like this (instead of of the fictional &
operator I made up?
Something like:
def match = "John 19" =~ /(&name&)\w+ (&age&\d+)/
def name = match.name
def age = match.age
Is there a groovy syntax that allows for something like this (instead of of the fictional &
operator I made up?
Assuming you are using on Java 7+, you can do:
If you are not on java 7 yet, you'd need a third party regex library
Alternative:
This doesn't name the groups, but a closure does parameterise the match:
which outputs:
This is a useful reference: http://naleid.com/blog/2008/05/19/dont-fear-the-regexp/