Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
595 views
in Technique[技术] by (71.8m points)

jenkins - convert list of map String to List of map as object List in groovy

i have an String object and i want to convert to List . in this list are List of maps .

String Object is :

def listOfmap = [[ip:'10.10.10.10',cronformat:'0 2,3,5 * * * *'],[ip:'20.20.20.20',cronformat:'0 */1 * * * *'],[ip:'30.30.30.30',cronformat:'15 * * * * *']]

and i used this code for convert :

listOfmap.eachMatch( /[[]?([^[],]+)[,]]?/ ){ a << it[ 1 ] }

and i want to result listOfmap[0] will be :

[ip:'10.10.10.10',cronformat:'0 2,3,5 * * * *']

but result is :

listOfmap[0] = [ip:'10.10.10.10'
listOfmap[1] = cronformat:'0 2
listOfmap[2] = 3
listOfmap[2] = 5 * * * * 

please help me . tnx


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Use this regex instead: [[]?([^[]]+)]]?

EDIT

To include also the [ square brackets use: ([[]?[^[]]+])


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...