0
def val = "[name: searchBaseDN value: , name: enable value: false, name: userDn value:  
cn=EAGREAD,ou=Users,ou=Administration,o=hyn, name: base value:  , name: prefsize value: 1,   
name: timeBetweenEvictionRuns value: 300000]"

I would like to convert it into hashmap val[name:value]

Thanks for your help .

4

1 回答 1

1

这看起来很有希望:

matches = val =~ /name:\s+(.*?)\s+value:\s+(.*?)(,\s+|\s+|])/

def newVal = [:]
matches.each { m ->
    newVal[m[1]] = m[2]
}

但是如果字符串稍微改变,正则表达式可能会中断......

于 2013-07-17T06:04:10.560 回答