读书人

Regex.Matches 怎么从网页中获取想要的

发布时间: 2013-07-08 14:13:00 作者: rapoo

Regex.Matches 如何从网页中获取想要的数据
网页中有这样一个table
<table style=" height:100%;table-layout:fixed;word-break: break-all" class="QUERYGRID" id="datagrid"><tbody><tr></tr></tbody></table>

如何用一下方法获取
string Pattern2 = @"<table id=""datagrid"".*?</table>";
MatchCollection Matches2 = Regex.Matches(strResult, Pattern2); MatchCollection? Regex
[解决办法]
试试
(?i)<table[^>]*?id=(['""]?)datagrid\1[^>]*?>[\s\S]*?</table>
[解决办法]

一个匹配用Regex.Match
多个匹配用Regex.Matches

(?is)<table[^>]*?id=""datagrid""[^>]*?>.*?</table>

string Pattern2 = @"(?is)<table[^>]*?id=""datagrid""[^>]*?>.*?</table>";
Match Matches2 = Regex.Match(strResult, Pattern2);
Console.WriteLine(Matches2.Value);

读书人网 >C#

热点推荐