111,126
社区成员
发帖
与我相关
我的任务
分享
string html = @"<div class=""c"" id=""C_3448822217297814"">
<a href=""/u/256822820?vt=4&"">
Baby_MR_GaG
</a>
。。。。。。。。。。。。。。。。。好多1
</div>
<div></div>
<div class=""c"" id=""C_3448822217297814"">
<a href=""/u/256822820?vt=4&"">
Baby_MR_GaG
</a>
。。。。。。。。。。。。。。。。。好多1
</div>
<div></div>
<div class=""c"" id=""C_3448822217297814"">
<a href=""/u/256822860?vt=4&"">
Baby_MR_GaG
</a>
。。。。。。。。。。。。。。。。。好多1
</div>
<div></div>";
string pattern = @"(?is)<a\s*href=""[^""]+""[^>]*>(.*?)</a>";
MatchCollection mc = Regex.Matches(html, pattern);
foreach (Match m in mc)
{
Console.WriteLine(m.Group[1].Value.Trim());//去掉收尾空格
}
//或者
string pattern = @"(?is)(?<=<a\s*href=""[^""]+""[^>]*>).*?(?=</a>)";
MatchCollection mc = Regex.Matches(html, pattern);
foreach (Match m in mc)
{
Console.WriteLine(m.Value.Trim());//去掉收尾空格
}
/*
Baby_MR_GaG
Baby_MR_GaG
Baby_MR_GaG
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.IO;
namespace sxLdfang
{
class Program
{
static void Main(string[] args)
{
string html = @"<div class=""c"" id=""C_3448822217297814"">
<a href=""/u/256822820?vt=4&"">
Baby_MR_GaG
</a>
。。。。。。。。。。。。。。。。。好多1
</div>
<div></div>
<div class=""c"" id=""C_3448822217297814"">
<a href=""/u/256822820?vt=4&"">
Baby_MR_GaG
</a>
。。。。。。。。。。。。。。。。。好多1
</div>
<div></div>
<div class=""c"" id=""C_3448822217297814"">
<a href=""/u/256822860?vt=4&"">
Baby_MR_GaG
</a>
。。。。。。。。。。。。。。。。。好多1
</div>
<div></div>";
string pattern = @"(?m)(?<=<a href=""/u/\d+\?vt=4&"">)[^<]*(?=</a>)";
MatchCollection mc = Regex.Matches(html, pattern);
foreach (Match m in mc)
{
Console.WriteLine(m.Value);
}
Console.ReadKey();
}
}
}
运行结果:
Baby_MR_GaG
Baby_MR_GaG