jmeter - my regex doesn't work. Tried to get something between 2 strings in response

33 Views Asked by At

I've got this kind of response.

</api/sale/mailboxApplications/confirm-email?verificationCode=SPTp%2FMl6Dbmqn3%2BlN0nsIfBIqmAN16Tc%2F4Hy30VIjb50US%2FRHRlzoKFRg4JjFBxeHmpecJCaiuZwtUCtVL3ELQDfw2USXHQt6Nmx87KUSzepmhlWvcXLgwLqL0vYR2Py4%2B6Fu9TIijAPrWbxPJ%2F9eelmqfzGrtxbd8Vu9u9LcrI%3D&amp;applicationId=3c77be27-98bd-4fac-bbf8-cfa201ce1a24

or

/api/sale/mailboxApplications/confirm-email?verificationCode=%2B1YDDRKZUi7D5nMsArlhnn6eOPtIp6aWM%2BVv6fg8OjzcBcPQI5bAQq3pHuJq8O7T0LmRrzfcwrd71VfZ2VCHVUOSGCaSa1np6XYQ0sswIPBFzepUMFi%2FynWRvrNhgA0fhvsC56nNArhYPcnghsTnRyUod%2BiS6u6CDTlYvmqzKsc%3D&amp;applicationId=733f125b-61bd-4876-aded-ed95f02da4c4 </pre>

My problem is that I can't get "verificationCode" from this response, which is between "verificationCode=" and "&amp"

I tried this kind of regex but none of them worked: (?<=verificationCode=)(.*\n?)(?=&amp) (?<=verificationCode=).*?(?=&amp) (?<=verificationCode=)(.+)(?=&amp) (?<=verificationCode=)(.*)(?=&amp)

Every time, jmeter returns "0" as a default value.

I have checked every of these regexes in https://regex101.com/ and they work well up there What I have missed?

enter image description here

3

There are 3 best solutions below

0
Emil On

Nevermind. I put verificationCode=(?s)(.*)&amp and set group number as $1$

Works fine

0
Dmitri T On

If you want to get something between 2 strings just go for the Boundary Extractor, all you need to do is to provide "left" and "right" boundary and it will get everything in-between

enter image description here

More information: The Boundary Extractor vs. the Regular Expression Extractor in JMeter

If you're still looking for a regular expression it would be something like:

verificationCode=(.+?)&amp

enter image description here

0
Reilas On

As a reference, there's no need to capture the value since you are utilizing the positive look-around syntax.

For the example, the following "match" will return the text only within the two values.

(?<=verificationCode=).+(?=&amp;)

If you do plan on capturing, remove the look-around syntax, as this will double the amount of steps to complete, for no reason.

verificationCode=(.+)&amp;