regex for html parsing (in c#)

2019-05-07 04:18发布

I'm trying to parse a html page and extract 2 values from a table row. The html for the table row is as follows: -

<tr>
<td title="Associated temperature in (ºC)" class="TABLEDATACELL" nowrap="nowrap" align="Left" colspan="1" rowspan="1">Max Temperature (ºC)</td>
<td class="TABLEDATACELLNOTT" nowrap="nowrap" align="Center" colspan="1" rowspan="1">6</td>
<td class="TABLEDATACELLNOTT" nowrap="nowrap" align="Center" colspan="1" rowspan="1"> 13:41:30</td>
</tr>

and the expression I have at the moment is:

<tr>[\s]<td[^<]+?>Max Temperature[\w\s]*</td>[\s]
<td[^<]+?>(?<value>([\d]+))</td>[\s]
<td[^<]+?>(?<time>([\d\:]+))</td>[\s]</tr>

However I don't seem to be able to extract any matches. Could anyone point me in the right direction, thanks.

7条回答
地球回转人心会变
2楼-- · 2019-05-07 04:51

When you write <td[^<]+?> I guess you really mean <td[^>]*>

That is "opening brace, td, maybe stuff other than closing brace..."

查看更多
登录 后发表回答