Reputation: 13
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 .
Upvotes: 0
Views: 396
Reputation: 2261
This looks promising:
matches = val =~ /name:\s+(.*?)\s+value:\s+(.*?)(,\s+|\s+|])/
def newVal = [:]
matches.each { m ->
newVal[m[1]] = m[2]
}
But if the string is changed slightly, the regex might break...
Upvotes: 1