首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

像这种时间能用正则提取吗解决方案

2013-08-04 
像这种时间能用正则提取吗 ·a classa01 target_blank hrefa.jsp?id1新闻标题1/a---[2013-07

像这种时间能用正则提取吗
 ·
<a class="a01" target="_blank" href="a.jsp?id=1">新闻标题1</a>
---[2013-07-18]
<br>
   ·
<a class="a01" target="_blank" href="a.jsp?id=2">新闻标题2</a>
---[2013-07-18]
<br>
   ·
<a class="a01" target="_blank" href="a.jsp?id=3">新闻标题3</a>
---[2013-07-18] 

分别提取链接网址,链接标题及时间,看有没有好的正则写法
即提取a.jsp?id=1
新闻标题
2013-07-18等
[解决办法]

string str = "html字符串";
            Regex.Matches(str, @"(?is)<a.*?href=[""']([^""']+)[^>]*>([^<]*)</a>\s*\-+\[([^\]]+)\]").OfType<Match>()
                .Select(t => new
                {
                    href = t.Groups[1].Value,
                    value = t.Groups[2].Value,
                    date = t.Groups[3].Value
                }).ToList().ForEach(t => Console.WriteLine(t.href + "\t" + t.value + "\t" + t.date));

热点排行