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

求个正规表达式~~~~~
我想把 <a   href= "cn/about/brief/index.jsp "   class= "font "> 学校简介 </a> 中的cn/about/brief/index.jsp和 "学校简介 "取出来,怎样用正规表达式实现。

------解决方案--------------------
匹配一个,这样
string yourStr = ............;
Match m = Regex.Match(yourStr, @ " <a[^ <]*?href=(([ ' " "])?(? <url> [\s\S]*?)\2|(? <url> \S*))[^> ]*?> (? <text> [^ <]*?) </a> ", RegexOptions.IgnoreCase);
if (m.Success)
{
richTextBox2.Text += m.Groups[ "url "].Value + "\n ";
richTextBox2.Text += m.Groups[ "text "].Value + "\n ";
}

匹配多个,这样
string yourStr = ............;
MatchCollection mc = Regex.Matches(yourStr, @ " <a[^ <]*?href=([ ' " "])?(? <url> [^ ' " "\s> ]*)\1?[^> ]*?> (? <text> [^ <]*?) </a> ", RegexOptions.IgnoreCase);
foreach (Match m in mc)
{
richTextBox2.Text += m.Groups[ "url "].Value + "\n ";
richTextBox2.Text += m.Groups[ "text "].Value + "\n ";
}