Enock Prince
Enock Prince

Reputation: 141

Jmeter - Regular expression to stop at first match

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...

Upvotes: 0

Views: 731

Answers (2)

UBIK LOAD PACK
UBIK LOAD PACK

Reputation: 34536

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:

Upvotes: 1

Dmitri T
Dmitri T

Reputation: 168092

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

Upvotes: 1

Related Questions