日期:2014-05-19  浏览次数:20403 次

关于用正则表达式解析html文件
例如有这样一段html代码:
<table   width=100%     border=0   cellpadding=0   cellspacing=0> <tr> <td> <img   src= 'images/article_common.gif '   alt= '普通文档 '> &nbsp; <a   href= 'Article_Show.asp?ArticleID=1116 '   title= '文档标题:最高人民法院关于规范行政案件案由的通知(法发[2004]2号)
文档作者:佚名
更新时间:2005-11-10   12:15:02
点击次数:1846 '   target= '_blank '> 最高人民法院关于规范行政案件案由的通知(法发[2004]… </a> <img   src= 'images/hot.gif '   alt= '热点文档 '> </td> <td   align=right> [佚名| <font   color=#999999> 2005年11月10日 </font> |1846] </td> </tr> </table> <table   width=100%     border=0   cellpadding=0   cellspacing=0> <tr> <td> <img   src= 'images/article_common.gif '   alt= '普通文档 '> &nbsp; <a   href= 'Article_Show.asp?ArticleID=672 '   title= '文档标题:关于加强广告执法办案协调工作的指导意见(试行)
文档作者:佚名
更新时间:2004-9-27   11:24:00
点击次数:1128 '   target= '_blank '> 山西6部新法规获省人大常委会通过 </a> <img   src= 'images/hot.gif '   alt= '热点文档 '> </td> <td   align=right> [佚名| <font   color=#999999> 2004年9月27日 </font> |1128] </td> </tr> </table> <table   width=100%     border=0   cellpadding=0   cellspacing=0> <tr> <td> <img   src= 'images/article_common.gif '   alt= '普通文档 '> &nbsp; <a   href= 'Article_Show.asp?ArticleID=506 '   title= '文档标题:我国首部循环经济法规出台
文档作者:佚名
更新时间:2004-9-27   11:22:05
点击次数:1039 '   target= '_blank '> 我国首部循环经济法规出台 </a> <img   src= 'images/hot.gif '   alt= '热点文档 '> </td> <td   align=right> [佚名| <font   color=#999999> 2004年9月27日 </font> |1039] </td> </tr> </table>
                    </td>
                </tr>
            </table>
  我要获得像 <a   href=> </a> 这样格式中的连接地址和title(标题)
我将如何用正则表达式解析呢?

------解决方案--------------------
不懂 友情UP
------解决方案--------------------
document.title
------解决方案--------------------
如果考虑href=后面可能为“ '”,“ "”或者直接接网址,可以这样改下,否则用我上面写的即可

string yourStr = ..............;
MatchCollection mc = Regex.Matches(yourStr, @ " <a[^> ]*?href=([ ' " "])?(? <url> [^ ' " "\s> ]*)\1?[^> ]*?title=([ ' " "])(? <title> [^ ' " "]*?)[ ' " "][^> ]*?> ", RegexOptions.IgnoreCase);
foreach(Match m in mc)
{
richTextBox2.Text += m.Groups[ "url "].Value + "\n "; //链接
richTextBox2.Text += m.Groups[ "title "].Value + "\n "; //标题
}