0

I want to write regular expression extractor for following:

</td><td>
                        <a href="/Service/Details/118?OID=544" title="Click to view details">118</a>
                    </td><td>
                        <img src="/Media/Images/Opr/544.png" title="" />
                    </td><td style="1">
                        1

I wrote it as below:

</td><td>
                    <a href="/Service/Details/(.+?)?OID=(.+?)" title="Click to view details">(.+?)</a>
                </td><td>
                    <img src="/Media/Images/Opr/(.+?).png" title="" />
                </td><td style="1">
                   (.+?)

but it is not working. please help.

1

There is an option multi line mode which you can use to extract string from multiline.

Reference :- http://jmeter.apache.org/usermanual/regular_expressions.html

Extract :- The single-line (?s) and multi-line (?m) modifiers are normally placed at the start of the regex.

Example:- Try single line mode for jmeter Extract "String" here

Regular expression would be : (?s)Try single line mode for jmeter.?Extract "(.?)" here

Output:- String

Let me know if you have any question

0

I doubt regular expressions will help there, would rather suggest going for one of the following:

If you need assistance in creating a relevant CSS/Query or XPath expression - update your question with more lines so it would be possible to see DOM tree, preferably upload full page source code somewhere.

0

The only issue with your regex is that your regex contains special (meta) characters like '<', '/' etc. which are being used as expression without using the escapes character. Such characters must be escaped by preceding them with \ (backslash) in order to treat them as ordinary characters, else your regex will throw error and will not work.

List of such characters can be obtained from the mentioned link.

1.  ( ) - grouping
2.  [ ] - character classes
3.  { } - repetition
4.  * + ? - repetition
5.  . - wild-card character
6.  \ - escape character
7.  | - alternatives
8.  ^ $ - start and end of string or line

I modified your regex with '\' escapes character and it is working fine e.g.

href=\"\/Service\/Details\/(.+?)\?OID=(.+?)" title="Click to view details"\>(.+?)\<\/a\>

this gives me 118, 544 and 118

Try with escape character and it should work fine. Also, if you want to pass them as parameters to other requests, better is to use multiple post request regex extractor in same request with different parameters name.

JMeter also provides the Regex tester in Tree view, where you can test your regex before implementing or you can test it online from this site (many other such sites are available for regex testing).

Update:

OP asked to extract value from 4th line

HTML:

</td><td>
                        <a href="/Service/Details/118?OID=544" title="Click to view details">118</a>
                    </td><td>
                        <img src="/Media/Images/Opr/544.png" title="" />
                    </td><td style="1">
                        1

Regex:

<\/td><td>
                        <a href="\/Service\/Details\/(.+?)\?OID=(.+?)" title="Click to view details">(.+?)<\/a>
                    <\/td><td>
                        <img src="\/Media\/Images\/Opr\/(.+?).png" title="" \/>
                    <\/td><td style="1">
                        1

Output: 118, 544, 118, 544

  • hI Dhiman, extracting only first line is not my problem that works fine for me. here problem is multiline. if you see I also want to extract something from 4th line after </td><td style="1"> – maitray bhatt May 3 '16 at 13:40
  • You can do that too, just add escape character wherever you find the special character. First line was just an example for your issue. Also, as I mentioned if you want to extract multiple values, then you multiple Regex Post Request Processor in JMeter, this way you will be able to extract single value and pass it to next required request using variable name. I have updated my answer for the required answer too. Let me know if you need something else. – Dhiman May 3 '16 at 17:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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