0

I have multiple HTML tags in the HTML response that I get which is basically values inside a Select Drop Down. I need to get value of a specific attribute when I know the text inside the HTML tag which is the name of the value being selected in the dropdown.

For eg.

<option value="01" id="01" >ABC</option>                        
<option value="02" id="02" >XYZ</option>  

multiple option tags like this. etc.

I have the value ABC/XYZ in a variable and based on that variable I need to get the value inside the "value" attribute using Regex.And Regex is the only way supposed to be used.

Value from "value" tag is what I would need to fetch,if it is the whole data under the tag for ABC value would also suffice.

I tried with the below regex but this seems to be giving wrong results when the data is changed.The below expression tries to return the whole content from the option tag which meets the condition. (?<=option)(?=[^#]*ABC)[^#]+(?=

Rohith
  • 11
  • 4
  • 3
    [Do not attempt to parse HTML with regular expressions.](https://stackoverflow.com/questions/701166/can-you-provide-some-examples-of-why-it-is-hard-to-parse-xml-and-html-with-a-reg) Use a dedicated HTML parser. – VGR Dec 13 '18 at 17:11
  • jsoup: Java HTML Parser: https://jsoup.org/ – Pedro Lobito Dec 13 '18 at 17:25
  • Can you provide the `url` to the html you're trying to search? – Pedro Lobito Dec 13 '18 at 17:27
  • I am doing this from Jmeter and I am not supposed to add the Jsoup library here. I am not able to extract this value with xpath or either CSS as nothing seems to work. – Rohith Dec 14 '18 at 10:03
  • A regex to get the entire content in that specific option tag would also suffice my requirement here. – Rohith Dec 14 '18 at 10:36

0 Answers0