JMeter: How to use Regular Expression to extract the value of a duplicate field?

后端 未结 7 788
名媛妹妹
名媛妹妹 2021-01-17 02:35

I have the following Response Body JSON:

{
    \"address\": [
    {
        \"id\": \"1234\"
    }
    ],
    \"id\": \"d1a4f010-48d9-434b-9b3a-2d2b12f5e38c\         


        
7条回答
  •  醉酒成梦
    2021-01-17 03:16

    Using JMeter, you can use Regular Expression Extractor ...

    Reference Name: myid
    Regular Expression: "id": "(.+?)"
    Template: $1$
    Match No.: 2
    

    If you specify using a Match No:...

    0 = Random Match
    1 = First Match 
    2 = Second Match
    etc....
    

    Or use corresponding variable to access the match. ${myid_2}

    The variables are set as follows:

    myid_matchNr - Number of matches found, possibly 0
    myid_n       - (n = 1, 2, etc..) Generated by the template
    myid_n_gm    - (m = 0, 1, 2) Groups for the match (n) 
    myid         - By itself it is always set to the default value
    myid_gn      - Not set at all
    

    Or judging by this case, if you prefer just regex and your strings are exactly as stated. You could do..

    ],\s+"id": "(.+?)"
    

提交回复
热议问题