Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何从具有各种嵌套表标记的html页面中仅提取第一个表标记_Html_Regex_C# 4.0 - Fatal编程技术网

如何从具有各种嵌套表标记的html页面中仅提取第一个表标记

如何从具有各种嵌套表标记的html页面中仅提取第一个表标记,html,regex,c#-4.0,Html,Regex,C# 4.0,我有下面的html页面。我只想提取C#中第一个表标记内的数据。html页面代码为: <table cellpadding=2 cellspacing=0 border=0 width=100%> <tbody> <tr> <td align=right><b>11/09/2013&nbsp;at&nbsp;09:48</b></td> </tr> </tbody> <

我有下面的html页面。我只想提取C#中第一个表标记内的数据。html页面代码为:

<table cellpadding=2 cellspacing=0 border=0 width=100%>
<tbody>
<tr>
<td align=right><b>11/09/2013&nbsp;at&nbsp;09:48</b></td>
</tr>
</tbody>
</table>
<center>
<table border="1" bordercolor="silver" cellpadding="2" cellspacing="0" width="100%">
<thead>
<tr>
<th width=100>ETA</th>
<th width=100>Ship Name</th>
<th width=80>From port</th>
<th width=80>To berth</th>
<th width=130>Agent</th>


</tr>
</thead>
<tbody>
<tr><td>11/09/2013 at 09:00&nbsp;</td>
<td>SONANGOL KALANDULA&nbsp;</td>
<td>Cabinda&nbsp;</td>
<td>Valero 6&nbsp;</td>
<td>Graypen&nbsp;</td>
</tr>
</tbody>
</table>
但是通过这个,我得到了整个页面的源代码,也就是我得到了所有表标记之间的数据,但是我只需要第一个表标记之间的文本


有谁能告诉我正则表达式,我只能用它从整个html页面中提取这一特定部分吗?

在这里试用您的版本时,它似乎对您指定的输入有效,尽管
[]*
实际上应该是
[]*
表示集合中任意数量的字符:)

不过,这似乎需要简化。这也应该起作用:

<table[^>]*>.*?</table>
]*>.*?

当然,如果您有嵌套的表,那么所有的赌注都没有了。

您考虑过使用html解析器吗?这正是正则表达式不是处理html输入的方式的场景。如果您有一组有限的已知HTML,正则表达式可能是一个快速的解决方案。但它们无法处理的恰恰是深度未知的嵌套标记。我还建议您为此使用HTML解析器。
<table[^>]*>.*?</table>