Groovy/Grails: Get key:value pairs satisfying a regexp -
I have a map and want to get all the keys: Add value where the key corresponds to a regular expression I have A solution where I find the key (for the key) and loop first through grep. But there should be a simple solution (or I'm hoping).
Ex:
def qmap = [name: "hair", style: 'direct', color_1 : 'brown' , Color_2: 'blonde', color_3: 'black'] I would like to get a submap with colors only. def color = [color_1: 'brown', color_2: 'blonde', color_3: 'black']
I can get keys using .grep, but it Only gives me the keys and I need a loop to get value.
def colorKeys = qmap.keySet (). Grep (~ / ^ color. * /) How to do any idea?
you can
qmap.subMap (colorKeys)
Comments
Post a Comment