2

I am trying to extract a value from HTML response but unable to. Can anyone please help me with regular expression for the below response. I tried below regular expression but, it is capturing whole response starting from Select to '"'.

I need to extract value 2 from the highlighted line in response.

Select Region<\/option>.*<option selected="selected" value="(.+?)"   

Input:

        <div class="col-lg-3 col-md-4 col-sm-12 form-group ">
            <label>      Region</label>
            <select class="Grid="0" id="RegionId" name="RegionId"><option value="">Select Region</option>
                <option value="9">IDX-ACO REGION CA</option>
                <option value="1">IDX-REGION I</option>
                **<option selected="selected" value="2">IDX-REGION II</option>**
                <option value="3">IDX-REGION III</option>
                <option value="5">IDX-REGION IV</option>
            </select>      
        </div>
bobble bubble
  • 16,888
  • 3
  • 27
  • 46
Siva
  • 35
  • 3

2 Answers2

3

Using regular expressions for parsing HTML is not the best idea.

JMeter comes with CSS Selector Extractor which provides option to extract various attributes values via CSS Selectors.

In your case it would be something like:

option[selected=selected]

if you want to include the parent <select> tag:

select[id=RegionId] option[selected=selected]

in both cases the attribute will be value

Demo:

enter image description here

More information: How to Use the CSS/JQuery Extractor in JMeter

Dmitri T
  • 159,985
  • 5
  • 83
  • 133
  • Thanks Dmitri. Yes, I have to add select tag as well and your solution works fine. – Siva Aug 10 '23 at 11:39
  • So, if I have multiple select tags like select[id=RegionId], select[id=SiteId], select[id=ProductId] in the response but option tag is same everywhere like option[selected=selected], should I add multiple CSS Selector Extractor or we can extract all the values in one go? – Siva Aug 10 '23 at 11:42
1

This RegEx will do the job

/<option selected="selected" value="\d+">(.*?)<\/option>/mg
hex494D49
  • 9,109
  • 3
  • 38
  • 47