string aa="<table><tr><td><a href=1.hmt target=_blank>链接1</a></td></tr>><tr><td><a href=2.hmt>链接2</a></td></tr>......</table>"
我想取得链接和文本 放到一个二维数组里:
1.htm 链接1
2.htm 链接2
............
请问如何实现?
<a[\s]+href=(?<Link>[^\s>]+)[^>]*>(?<Text>[^<]*)</a>
取Link和Text组.
完整的控制太应用程序代码(已经通过测试):
----------------------------------------
using System;
using System.Text.RegularExpressions;
public class RegularExpressions
{
static void Main()
{
string strMy="<table><tr><td><a href=1.hmt target=_blank>链接1</a>"
+"</td></tr>><tr><td><a href=2.hmt>链接2</a></td></tr>..</table>";
string[,] arrMy=new string[2,2];
string strPattern=@"<a[\s]+href=(?<Link>[^\s>]+)[^>]*>(?<Text>[^<]*)</a>";
MatchCollection Matches=Regex.Matches(strMy,
strPattern,
RegexOptions.IgnoreCase);
int i=0;
foreach(Match NextMatch in Matches)
{
arrMy[i,0]=NextMatch.Groups["Link"].Value.ToString();
arrMy[i,1]=NextMatch.Groups["Text"].Value.ToString();
Console.WriteLine("arrMy[{0},0]:{1}\narrMy[{2},1]:{3}",
i,arrMy[i,0],i,arrMy[i,1]);
i++;
}
Console.ReadLine();
}
}
----------------------------------------------------------------------------------
可以揭帖了!