0

I want to get 2269 from below html response. I use

<td>XYZ Market Services \(Sydney\)</td>(?s).*name="addCompany" value="(.+?)" 

Regular Expression with $1$ template and match number 1. but it returns 2271. Somebody please help me to create a regular expression to get the value 2269.

        <tr>
            <td>XYZ Market Services (Sydney)</td>
            <td class="center">
                <form action="/FormBuilder/pages/Folders/add.aspx?group=1424sfksdfsdgdsf243-3Q-w&ajax=true" method="post">
                    <input name="addCompany" value="2269" type="hidden" /><input class="XYZLookAlike" type="button" onclick="fnload(this)" value="Add" />
                </form>
            </td>
        </tr>

        <tr>
            <td>XYZ Market Services (Melbourne)</td>
            <td class="center">
                <form action="/FormBuilder/pages/Folders/add.aspx?group=1424sfksdfsdgdsf243-3Q-w&ajax=true" method="post">
                    <input name="addCompany" value="2271" type="hidden" /><input class="XYZLookAlike" type="button" onclick="fnload(this)" value="Add" />
                </form>
            </td>
        </tr>

Thank you...

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563
Enock Prince
  • 141
  • 2
  • 13
  • 1
    [H̸̡̪̯ͨ͊̽̅̾̎Ȩ̬̩̾͛ͪ̈́̀́͘ ̶̧̨̱̹̭̯ͧ̾ͬC̷̙̲̝͖ͭ̏ͥͮ͟Oͮ͏̮̪̝͍M̲̖͊̒ͪͩͬ̚̚͜Ȇ̴̟̟͙̞ͩ͌͝S̨̥̫͎̭ͯ̿̔̀ͅ](https://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags) - but anyway, just use a lazy quantifier: `.*?`. Also, change `value="(.+?)"` to `value="([^"]*)"` – ctwheels Jan 09 '18 at 14:09

2 Answers2

1

Don't use regular expressions to parse HTML, there are way better options.

For example you can use XPath Extractor which allows executing arbitrary XPath queries against the response, here is an example of extracting value attribute for addCompany input where column text is XYZ Market Services (Sydney)

//td[text()='XYZ Market Services (Sydney)']/following-sibling::*/form/input[@name='addCompany']/@value

Demo:

JMeter XPath Extractor

More information: Using the XPath Extractor in JMeter

Dmitri T
  • 159,985
  • 5
  • 83
  • 133
  • @Dmitri, it is strange that you advise using XPath Extractor for HTML ? AFAIK it is the worst in terms of performances and it requires running jtidy before being able to execute XPath so I don't think this is the correct answer. – UBIK LOAD PACK Jan 09 '18 at 20:41
  • 1
    If you don't consider this answer a good one there is a ▼ sign next to it, next time could you please use it instead of verbal exercises and let the TS and/or the community decide which option is right. – Dmitri T Jan 09 '18 at 22:11
1

To parse HTML, the best extractor is CSS/JQuery extractor in terms of Maitainability/easyness/performance is:

enter image description here

See this regarding performances of extractors:

UBIK LOAD PACK
  • 33,980
  • 5
  • 71
  • 116