0

I can get the match I want from a large string of HTML using (?<=Var#2).*?(?=tr>). It's then from that match I'd like to find a match, the word "available". Using that RegEx in this simple example:

 <tr class="product-row">
        <td class="product-name">Var#1</td>
        <td class="product-day">
          <div class="status-container end-marker">
          <a class="status-icon available"></a></div></td>
 </tr>
<tr class="product-row">
        <td class="product-name">Var#2</td>
        <td class="product-day">
          <div class="status-container end-marker">
          <a class="status-icon available"></a></div></td>
 </tr>
<tr class="product-row">
        <td class="product-name">Var#3</td>
        <td class="product-day">
          <div class="status-container end-marker">
          <a class="status-icon available"></a></div></td>
 </tr>

Continue with VAR# changing up to 9

It matches the section between "Var#2" and "/tr" then from this match I'd like to match the word "available". So the process would be match everything in-between "Var#2" and "/tr" and from that match find the word "available" but only between the match. Groups seems to be the way to go however all my tries have failed. Is it even possible?

Gewis
  • 1
  • 2
  • I feel compelled to tell you that using regex for XML parsing is considered bad practice for the reasons explained in this answer : https://stackoverflow.com/a/1732454/7156098 Can you tell us what is the main goal here, as in why matching "available" is required in your case ? I am sure there are better solutions than using regex. – alegria Sep 11 '22 at 11:47
  • It's being used in conjunction with a Nagios plugin that need to checks for the presents of the word "available" but only after looking at a certain part of a web page between the keywords "Var#2" and "/tr". The layout of the HTML is very static except for the word "available". A regex statement is one of the arguments fed to the plugin. Somewhat less complicated regex statements are currently being fed to the plugin and work fine. Good or bad I'm restrained by the plugin. – Gewis Sep 11 '22 at 14:19

0 Answers0