110,533
社区成员
发帖
与我相关
我的任务
分享
MatchCollection mc = Regex.Matches(html, @"(?is)<div class=""wdate"">.*?作者:黄正详.*?</div>(.*?<p>(?<data>.+?)</p>)+");
StringBuilder result = new StringBuilder();
foreach(Match m in mc)
{
foreach (Capture c in m.Groups["data"].Captures)
{
result.AppendLine(c.Value);//c.Value就是每一条的p中内容
}
}
Console.WriteLine(result.ToString());//这是所有的p中内容合起来后的结果
MatchCollection mc = Regex.Matches(html, @"(?is)<div class=""wdate"">.+</div>(.*?<p>(?<data>.+?)</p>)+");
StringBuilder result = new StringBuilder();
foreach(Match m in mc)
{
foreach (Capture c in m.Groups["data"].Captures)
{
result.AppendLine(c.Value);//c.Value就是每一条的p中内容
}
}
Console.WriteLine(result.ToString());//这是所有的p中内容合起来后的结果
Match m = Regex.Match(html, @"(?is)<div class=""wdate"">.+</div>(.*?<p>(?<data>.+?)</p>)+");
StringBuilder result = new StringBuilder();
foreach (Capture c in m.Groups["data"].Captures)
{
result.AppendLine(c.Value);//c.Value就是每一条的p中内容
}
Console.WriteLine(result.ToString());//这是所有的p中内容合起来后的结果
private static void TestRegex12()
{
string html = @"<div class=""wdate"">发表时间:2010-8-24 15:28:00</div>
<h2>标题</h2>
<P>内容1</P>
<P>内容1</P>
<P>内容1</P>
<P>内容1</P>
<P>内容1</P>
<P>内容1</P>
<P>内容1</P>
<P>内容1</P>
<P>内容1</P>
<P>内容1</P>
<P>内容1</P>
<P>内容1</P>
</div>
";
Match m = Regex.Match(html, @"(?is)<div class=""wdate"">.+</div>(.*?<p>(?<data>.+?)</p>)+");
StringBuilder result = new StringBuilder();
foreach (Capture c in m.Groups["data"].Captures)
{
result.AppendLine(c.Value);
}
Console.WriteLine(result.ToString());
}