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?