0

I am using JMeter and trying to write a Regular expression (regex) that can return the two digit class ID from some HTML option elements.

<option value="53">1ABC Class</option>
<option value="52">2XYZ Class</option>
<option value="69" selected="selected">001 Class</option>

using following regex..

value="..">1ABC Class<

returns

value="53">1ABC Class<

In the example given, the only return values I want are 53, 52 and 69.

I am looking for a regex that will work with all of above given options.

AeroX
  • 3,387
  • 2
  • 25
  • 39
TestingWithArif
  • 894
  • 2
  • 13
  • 19

3 Answers3

3

Never use regular expressions to parse HTML. Each time you use regular expressions to parse HTML somewhere somehow a kitten dies.

Go for CSS/JQuery Extractor

JMeter CSS Jquery Extractor

Go for XPath Extractor

JMeter XPath Extractor

But do me a favour, don't use regular expressions for HTML.

Community
  • 1
  • 1
Dmitri T
  • 159,985
  • 5
  • 83
  • 133
  • Thanks. Even though moustafa solution worked but I went with xpath extractor as suggested by wiktor. Will try CSS extractor later as well. – TestingWithArif Nov 29 '16 at 18:17
1

Try this:

value="(\d+)".*?>1ABC Class<

This will give the result in the brackets as the needed value only, plus it would match any tag.

MoustafaS
  • 1,991
  • 11
  • 20
0

Not Regex solution for c# or vb.net

var doc = XDocument.Parse(yourXmltext);
var options = doc.Root.Descendants("option");

foreach(var option in options)
{
    var value = option.Attribute("value").Value;
    var className = option.Value;
}

LINQ to Xml makes code little bid more readable

Fabio
  • 31,528
  • 4
  • 33
  • 72