Extract location response header with /

Hi, I appreciate if I can get some pointers how to extract a value.

I am trying to extract the id 494103 from the response header location with the following expression

.check(headerRegex(“Location”, “(\d+)”).saveAs(“cartId”))

HTTP response:
303 See Other
Content-Length: 0
Connection: keep-alive
Server: nginx/1.16.1
Location: /cartdetail?CartId=494103

However, I always get the error if found nothing, I wonder if the / at the beginning of the location header is the culprit, because I can extract other header such as Server no problem.

headerRegex((Location,(\d+))).find.exists, found nothing 1 (100.0%)

Appreciate the help.

Don’t try to parse Location header!
Gatling will automatically follow redirects by default and it would be a very bad idea to disable this behavior.

Instead you should check the currentLocation (the landing url), see https://gatling.io/docs/current/http/http_check/#page-location