1

I want to extract certain text from the response i get in jMeter but the issue is that the response is multiline and does not extract the value correctly. I have tried using multiline mode which got me somewhere but not fully. Here is the response:

                "category61B" : [ "Specified Insurance Company",
                    "Investment Entity", "Custodial Institution ",
                    "Depository Institution", "Other" ],

I want to extract every value inside the square brackets without ". Regex i wrote for this is:

(?s)\"category61B\" : [ \"([^"]+)\" which gave me:

Specified Insurance Company

I am not able to write further regex to get the other values.

Note: I tried online Regex Tester and it gave me the correct groups. Obviously i tried the same regex with jmeter and it gave me 0 matches but no errors.

The regex wrote there was:

(?s)\"category61B\" : \[ \"(.+?)\",\n\t\t\t\t\t\t\"(.+?)\", \"(.+?)\",\n\t\t\t\t\t\t\"(.+?)\", \"(.+?)\" ],

Update: I tried the below RegEx but this will result in capturing everything till the end of response.

(?s)"category61B".*\[(.*)\]

2 Answers 2

1

Try out: (?s)"category61B".*\[(.*)\], looking into RegExp Tester mode of the View Results Tree listener it should be something you're looking for

JMeter View Results Tree RegExp Tester


By the way, your response is utterly like to be a JSON structure so my expectation is that using JSON Extractor will much easier and as simple as $..category61B

2
  • Obligatory link to Regular Expressions: Now you have two problems
    – ernie
    Commented Apr 13, 2017 at 16:18
  • @Dmitri - Sorry but i forgot to mention this. I had already tried this but the issue with not using '?' is that it will capture everything till the end of the response which is a lot in this case. I have updated my question with this info.
    – MitSM
    Commented Apr 14, 2017 at 9:15
0

@MitSM

I have worked on query, you have posted.Please go through the details below hope it serves the purpose.

Regex I wrote in Jmeter and executed was:

(?m)"category61B" : \[ "(.*)\"\,\n                    "(.*)\"\, "(.*)\"\,\n                    "(.*)"\, "(.*)" \]\,
  1. Also, I have validated the another regex on regex101,which is :

    (?m)"category61B" : [ "(.)\"\,\n \s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s"(.)\"\, "(.)\"\,\n \s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s\s"(.)"\, "(.*)" ]\,

    Please find attached:"Regex_1"

Regex_1

  1. I have also executed it on Jmeter using jp@gc - Dummy Sampler and response you have provided.Refer post execution result :"Result" and you can utilize individual groups viz. categoryId_g1,categoryId_g2,categoryId_g3 etc. for every value inside the square brackets without ".

Result

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.