0

I have a HTML table that I need to parse using regex. It has a 'wide' format and can span multiple columns. Here's an example with 4 columns:

<div class="info">
   <table class="data-table" id="specs-table">
      <colgroup>
      </colgroup>
      <tbody>
         <tr class="border-bottom">
            <th class="border-bottom center">City</th>
            <th class="border-bottom center">time</th>
            <th class="border-bottom center">temperature</th>
            <th class="border-bottom center">cloud coverage</th>
         </tr>
         <tr>
            <td class="a-center data">Madrid</td>
            <td class="a-center data">13:49</td>
            <td class="a-center data">20 C</td>
            <td class="a-center data">23%</td>
         </tr>
      </tbody>
   </table>
</div>
City time temperature cloud coverage
Madrid 13:49 20 C 23%

I need to get the table headers with the proper data reading e.g.

City time temperature cloud coverage
City: Madrid time: 13:49 temperature: 20 C cloud coverage: 23%

Is there a way to do it with regex that could generalize to an unknown number of columns?

Xlrv
  • 400
  • 5
  • 16
  • I'm not sure what you're asking for here, and you seem to be imposing a solution rather than asking for one. Please revise to explain better what you're trying to accomplish. What's a "proper data reading", and what action are you taking once you find one? – isherwood Jan 13 '21 at 17:01
  • Also, I don't see any column spanning happening in your example. What does that refer to? – isherwood Jan 13 '21 at 17:01
  • It looks like you are looking to create a regex, but do not know where to get started. Please check [Reference - What does this regex mean](https://stackoverflow.com/questions/22937618) resource, it has plenty of hints. Also, refer to [Learning Regular Expressions](https://stackoverflow.com/questions/4736) post for some basic regex info. Once you get some expression ready and still have issues with the solution, please edit the question with the latest details and we'll be glad to help you fix the problem. – Wiktor Stribiżew Jan 13 '21 at 17:40

0 Answers0