Regex Group Extraction (json inside a HTML body)

Some developer thought that it would be a good idea to stash an entire json inside a HTML response body, something like:

//lots of html

Given this scenario I have to capture the deliveryCost.value value of the “code”:“normal” json object (in this case, 5.800).
I did a regex as follow:

.check(regex("\"code\":\"normal\"(.+?)\"value\":(.+?)}").exists.saveAs("deliveryCost"))

However in this case I have two matching groups and gatling is saving only the first one (or I’m miss interpreting its usage).

Is there any way to get the second group? I don’t mind about the first one, it is there just to show that there are more data in between.

I would love to simply use jsonpath, but I don’t know how to do it on this mixed scenario and there is no chance to change the code, the entire solution relies on this odd scenario and the developers are from another company abroad.

Thank you.

Ok, I found a really weird way for doing that.
I used the transform feature but I’m not happy (is it performatic? is it safe? I honestly don’t know).

val pattern = "\"value\":(.+)".r
.check(regex("\"code\":\"normal\"(.+?)}").transform(s => {
  var retorno = ""
  pattern.findAllIn(s).matchData.foreach(m => {
    retorno = m.group(1)
  })
  retorno
}).exists.saveAs("deliveryCost"))

Any other idea? I’m looking for a more elegant solution otherwise I’m gonna sticking to this one.