日期:2014-05-17  浏览次数:20763 次

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);