Need to get specific part of URL

Hello Team,

I need one help. I need to save one specific part of URL

This is the URL

And want to extract


and save it to url.

If the URL will always be the same size, then you can parse it using the “substring(startPosition, endPosition)” function, such as myUrl.substring(47, 79).

def myUrl = WebUI.getUrl()
def myContents = myUrl.substring(47, 79)
WebUI.comment("your contents are ${myContents}")

If the URL may not always be the same size, then you can try parsing it with the split("/") function, such as myUrl.split("/")[5]

def myUrl = WebUI.getUrl()
def myContents = myUrl.split("/")[5]
WebUI.comment("your contents are ${myContents}")

the 5 means we want the 6th item of the array that the split() creates (I think it’s the sixth we want) because the counting of arrays starts at zero.



URL url = new URL("")
String path = url.getPath()   
println path                  //    /24160553/checkouts/1209280661348825c36174f4f3bdce1b/thank_you

List elements = path.split("/") as List
elements.eachWithIndex({ e, index ->
	println "${index} ${e}"
println "wanted: " + elements[3]


1 24160553
2 checkouts
3 1209280661348825c36174f4f3bdce1b
4 thank_you
wanted: 1209280661348825c36174f4f3bdce1b
1 Like