Liu Xu
Liu Xu

Reputation: 37

How to grab substring in groovy?

May I know how to extract the substring "10111" from string "some infor [1:5] 10111" in groovy? The following code written by me, are there any better way to do this?

parentString = "some infor [1:5] 10111"
String childString = parentString
println childString.substring(16)

Upvotes: 0

Views: 185

Answers (1)

daggett
daggett

Reputation: 28564

def parentString = "some infor [1:5] 10111"
def childString  = parentString.replaceAll( /.*\[\d+:\d+]\s*(.*)/ , '$1' )
println childString

about regex: https://regex101.com/r/MWVdGX/1

Upvotes: 1

Related Questions