string s = "..........."; Regex re = new Regex(@"<a[^>]*href=(""(?<href>[^""]*)""|'(?<href>[^']*)'|(?<href>[^\s>]*))[^>]*>(?<text>.*?)</a>", RegexOptions.IgnoreCase | RegexOptions.Singleline); Match m = re.Match(s); if(m.Success) { string link = m.Groups["href"].Value; string text = Regex.Replace(m.Groups["text"].Value,"<[^>]*>",""); Console.WriteLine("link:{0}\ntext:{1}", link, text); } 过去看过saucer(思归)的一段,给你吧~
或用正则 这里有http://topic.csdn.net/t/20050730/19/4178683.html
http://topic.csdn.net/t/20061217/00/5236019.html
string s = "...........";
Regex re = new Regex(@"<a[^>]*href=(""(?<href>[^""]*)""|'(?<href>[^']*)'|(?<href>[^\s>]*))[^>]*>(?<text>.*?)</a>", RegexOptions.IgnoreCase | RegexOptions.Singleline);
Match m = re.Match(s);
if(m.Success)
{
string link = m.Groups["href"].Value;
string text = Regex.Replace(m.Groups["text"].Value,"<[^>]*>","");
Console.WriteLine("link:{0}\ntext:{1}", link, text);
}
过去看过saucer(思归)的一段,给你吧~