求正则

liuxing_99 2012-03-04 10:52:26
获取id=long这个div中的所有标签的值,如西甲第32轮,皇家马德里,古蒂,伊瓜因等

<div class=""info"" id=""long"" style=""display:none;"">

<div class=""item""></div>

<div class=""item""><span class=""label"">分类:</span><div class=""content"" id=""cateInfoId2""><script>document.getElementById(""cateInfoId2"").innerHTML=document.getElementById(""cateInfo"").innerHTML;</script></div><div class=""clear""></div></div>

<div class=""item""><span class=""label"">标签:</span><div class=""content""><a href=""http://www.soku.com/search_video/type_tag_q_%E8%A5%BF%E7%94%B2%E7%AC%AC32%E8%BD%AE"" charset=""400-8-3-0"" target=""_blank"">西甲第32轮</a> <a href=""http://www.soku.com/search_video/type_tag_q_08-09"" charset=""400-8-3-1"" target=""_blank"">08-09</a> <a href=""http://www.soku.com/search_video/type_tag_q_%E7%9A%87%E5%AE%B6%E9%A9%AC%E5%BE%B7%E9%87%8C"" charset=""400-8-3-2"" target=""_blank"">皇家马德里</a> <a href=""http://www.soku.com/search_video/type_tag_q_%E5%8F%A4%E8%92%82"" charset=""400-8-3-3"" target=""_blank"">古蒂</a> <a href=""http://www.soku.com/search_video/type_tag_q_%E4%BC%8A%E7%93%9C%E5%9B%A0"" charset=""400-8-3-4"" target=""_blank"">伊瓜因</a> <a href=""http://www.soku.com/search_video/type_tag_q_%E5%8A%B3%E5%B0%94"" charset=""400-8-3-5"" target=""_blank"">劳尔</a> <a href=""http://www.soku.com/search_video/type_tag_q_%E5%8D%A1%E8%A5%BF%E5%88%A9%E4%BA%9A%E6%96%AF"" charset=""400-8-3-6"" target=""_blank"">卡西利亚斯</a> <a href=""http://www.soku.com/search_video/type_tag_q_%E8%B5%AB%E5%A1%94%E8%8F%B2"" charset=""400-8-3-7"" target=""_blank"">赫塔菲</a> <a href=""http://www.soku.com/search_video/type_tag_q_%E5%B9%BF%E4%B8%9C%E4%BD%93%E8%82%B2"" charset=""400-8-3-8"" target=""_blank"">广东体育</a> </div><div class=""clear""></div></div>

<div class=""handle""><div style=""float:left;""><a href=""http://www.youku.com/service/feed/subtype/3/""

charset=""400-03-12"" target=""_blank"">举报</a> <a href=""http://www.youku.com/service/feed/subtype/2/"" charset=""400-03-11"" target=""_blank"">反馈</a></div><a onclick=""Display.changeBlock('short', 'long')"">隐藏</a></div>

</div>
...全文
117 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
夜色镇歌 2012-03-05
  • 打赏
  • 举报
回复
q107770540 2012-03-05
  • 打赏
  • 举报
回复
(?<=>)[^<>\s]+?(?=<)
风一样的大叔 2012-03-05
  • 打赏
  • 举报
回复
太难看懂了
冰镇宝贝321 2012-03-05
  • 打赏
  • 举报
回复
亲 你这代码让我们看的情何以堪,先规范下啊,看不懂了
殷小强 2012-03-05
  • 打赏
  • 举报
回复
亲,这代码太乱码了。天马行空呀。哈哈
wxach001 2012-03-05
  • 打赏
  • 举报
回复
将这个代码复制到console application 中并导入 using System.Text.RegularExpression;
就是你想要的结果
wxach001 2012-03-05
  • 打赏
  • 举报
回复
string str = @"<div class='info' id='long' style='display:none;'>

<div class='item'></div>

<div class='item'><span class='label'>分类:</span><div class='content' id='cateInfoId2'><script>document.getElementById('cateInfoId2').innerHTML=document.getElementById('cateInfo').innerHTML;</script></div><div class='clear'></div></div>

<div class='item'><span class='label'>标签:</span><div class='content'><a href='http://www.soku.com/search_video/type_tag_q_%E8%A5%BF%E7%94%B2%E7%AC%AC32%E8%BD%AE' charset='400-8-3-0' target='_blank'>西甲第32轮</a> <a href='http://www.soku.com/search_video/type_tag_q_08-09' charset='400-8-3-1' target='_blank'>08-09</a> <a href='http://www.soku.com/search_video/type_tag_q_%E7%9A%87%E5%AE%B6%E9%A9%AC%E5%BE%B7%E9%87%8C' charset='400-8-3-2' target='_blank'>皇家马德里</a> <a href='http://www.soku.com/search_video/type_tag_q_%E5%8F%A4%E8%92%82' charset='400-8-3-3' target='_blank'>古蒂</a> <a href='http://www.soku.com/search_video/type_tag_q_%E4%BC%8A%E7%93%9C%E5%9B%A0' charset='400-8-3-4' target='_blank'>伊瓜因</a> <a href='http://www.soku.com/search_video/type_tag_q_%E5%8A%B3%E5%B0%94' charset='400-8-3-5' target='_blank'>劳尔</a> <a href='http://www.soku.com/search_video/type_tag_q_%E5%8D%A1%E8%A5%BF%E5%88%A9%E4%BA%9A%E6%96%AF' charset='400-8-3-6' target='_blank'>卡西利亚斯</a> <a href='http://www.soku.com/search_video/type_tag_q_%E8%B5%AB%E5%A1%94%E8%8F%B2' charset='400-8-3-7' target='_blank'>赫塔菲</a> <a href='http://www.soku.com/search_video/type_tag_q_%E5%B9%BF%E4%B8%9C%E4%BD%93%E8%82%B2' charset='400-8-3-8' target='_blank'>广东体育</a> </div><div class='clear'></div></div>

<div class='handle'><div style='float:left;'><a href='http://www.youku.com/service/feed/subtype/3/'

charset='400-03-12' target='_blank'>举报</a> <a href='http://www.youku.com/service/feed/subtype/2/' charset='400-03-11' target='_blank'>反馈</a></div><a onclick='Display.changeBlock('short', 'long')'>隐藏</a></div>

</div>";
string pattern=@">\w+[^:]?<";
MatchCollection mc = Regex.Matches(str,pattern);
foreach (Match item in mc)
{
Console.WriteLine(item.Value.Substring(1,item.Value.Length-2));
}

62,052

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧