Extract url from response body and save it

My intention is to catch the url from response body and put it into the next request. For example I have the following request:
.exec(http(“goHome”).get("/"))

In the response I have the following piece:

<a href="./?1-1.Some_URL" wicket:id="addButton">Add something new</a>

What my request should be to save “./?1-1.Some_URL” as ${myUrl} in case "wicked:id=“addButton”?

P.S. I know that I need to use regex but I need some assist.

I tried the following function (I would also like to check if fetched url is the one I need):
val scenarioAddDeclarations = scenario(“addNew”)
.exec(http(“HomePage”).get("/")
.check(bodyString(
“”“Lisa uus deklaratsioon”"").saveAs(“myUrl”)))
.pause(2)
.exec((session:Session) => {
val myUrl = session.getAttributeAsOptionString
if(myUrl.isDefined){
println(myUrl.get)
}
session
})

But I get the error:

found : String("<a href=* wicket:id=“addNewKmd”>Lisa uus deklaratsioon")
required: io.gatling.core.session.Session

You’re regex is wrong. You want a capture group. And a * all by itself won’t work as expected.

You should:

Hi,

I followed your advice and used the online tester (great tool btw, thanks very much!). It seems that correct regex for fetching my url would be:
Lisa uus deklaratsioon

What about the other part of the code? Is the syntax correct?