日期:2014-05-17  浏览次数:20407 次

像这种时间能用正则提取吗
 ·
<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));