日期:2014-05-18 浏览次数:20995 次
Regex r = new Regex(@"(?is)(?<=id=""nbaVidRsltBody"")(?:(?!id=""nbaVidPagBtm"").)*(?=id=""nbaVidPagBtm"")");
Regex r = new Regex(@"(?is)(?<=id=""nbaVidRsltBody""[^>]+>).+?(?=id=""nbaVidPagBtm"")");
Regex re = new Regex(@"<div\b[^>]*?id=""nbaVidRsltBody""[^>]*>([\s\S]*?)<div\b[^>]*?id=""nbaVidPagBtm""[^>]*>", RegexOptions.IgnoreCase); Match match = re.Match(str); if(match.Success) { Console.WriteLine(match.Groups[1].Value); }
------解决方案--------------------
@"(?is)(?<=<div id=""nbaVidRsltBody""[^>]*>).+?(?=<div id=""nbaVidPagBtm"">)"
------解决方案--------------------
楼主怎么知道你给的两个正则没效果,用什么测试的,要么是你的测试数据有问题,要么是你的测试工具或代码有问题,你给的正则是可以取到结果的
string test = @"图挂掉了,具体情况看下面 <div id=""nbaVidRsltBody"" style....> ....(这里还有很多内容) <div id=""nbaVidPagBtm""> "; Regex r = new Regex(@"(?is)(?<=id=""nbaVidRsltBody""[^>]+>).*?(?=id=""nbaVidPagBtm"")"); MatchCollection mc = r.Matches(test); foreach (Match m in mc) { richTextBox2.Text += m.Value + "\n"; } /*-----输出----- ....(这里还有很多内容) <div */
------解决方案--------------------
建立一个txt文档,内容如下:
<div id="nbaVidRsltBody" style="visibility: visible; "> fdahslflkaslkashllfhads347r84<div id="nbaVidPagBtm"> <div id="nbaVidRsltBody" style="visibility: visible; ">1231<div id="nbaVidPagBtm"> <div id="nbaVidRsltBody" style="visibility: visible; ">dfs4<div id="nbaVidPagBtm"> <div id="nbaVidRsltBody" style="visibility: visible; "> f333ds<div id="nbaVidPagBtm"> <div id="nbaVidRsltBody" style="visibility: visible; "> fdse34434343<div id="nbaVidPagBtm">