How can i extract partial text from the URL

Suppose i get a URL in a String “https://www.amazon.in/gp/goldbox?ref_=nav_cs_gb_5bf06ae8328043a2beb2754f40a54c84
Now i have to extract “gp” which is there after amazon.in and between “/”

So How do I get only the “gp”, and use it to input in other menu?

I might look into the split function but it would depend on more information. The split function returns a list of Strings breaking the given url string into parts based on the parameter–in this case the slash. The list of Strings starts at zero, so I think we want the 4th string but you can play with the number if it doesn’t produce the correct phrase.

myVar = url.split("/")[3]
WebUI.comment('my var is ' + myVar)

Note: the contents within the split function is using Regex, so sometimes you have to “escape” the reference, like:

myVar = url.split("\\/")[3]

https://www.tutorialspoint.com/groovy/groovy_strings.htm

http://docs.groovy-lang.org/docs/groovy-1.7.3/html/groovy-jdk/java/lang/String.html

Thanks a lot the solution worked for me