//
得到下面字符串里“商品列表”的a的href
string pattern = @" <a href='([^']+)[^<]+'>商品列表 " ;
Regex r = new Regex(pattern, RegexOptions.IgnoreCase);
MatchCollection mc = r.Matches(data);
foreach (Match m in mc)
{
string ss = m.Groups[1].Value;
}
//这个是一般的a链接获取
//pattern = @"<a href='([^']+)";
测试数据:
<a href='http://goods.aaa.com/EsalesGoodsSortDict/EsalesGoodsSortDictList.aspx?KeyStr=a4142c6da5bf47019181f54c299606b0'onclick='javascript:SetSpan1("商品设置 >> 商品栏目列表");' target='contentiframe' id='a3'>商品栏目列表</a></li>
<li><a href='http://goods.aaa.com/EsalesGoodsClassDict/EsalesGoodsClassDictList.aspx?KeyStr=a4142c6da5bf47019181f54c299606b0'onclick='javascript:SetSpan1("商品设置 >> 商品类别列表");' target='contentiframe' id='a3'>商品类别列表</a></li>
<li> <a href='http://goods.aaa.com/EsalesGoodsInfo/EsalesGoodsInfoList.aspx?KeyStr=a4142c6da5bf47019181f54c299606b0'onclick='javascript:SetSpan1("商品设置 >> 商品列表");' target='contentiframe' id='a3'>商品列表</a>
string pattern = @" <a href='([^']+)[^<]+'>商品列表 " ;
Regex r = new Regex(pattern, RegexOptions.IgnoreCase);
MatchCollection mc = r.Matches(data);
foreach (Match m in mc)
{
string ss = m.Groups[1].Value;
}
//这个是一般的a链接获取
//pattern = @"<a href='([^']+)";
测试数据:
<a href='http://goods.aaa.com/EsalesGoodsSortDict/EsalesGoodsSortDictList.aspx?KeyStr=a4142c6da5bf47019181f54c299606b0'onclick='javascript:SetSpan1("商品设置 >> 商品栏目列表");' target='contentiframe' id='a3'>商品栏目列表</a></li>
<li><a href='http://goods.aaa.com/EsalesGoodsClassDict/EsalesGoodsClassDictList.aspx?KeyStr=a4142c6da5bf47019181f54c299606b0'onclick='javascript:SetSpan1("商品设置 >> 商品类别列表");' target='contentiframe' id='a3'>商品类别列表</a></li>
<li> <a href='http://goods.aaa.com/EsalesGoodsInfo/EsalesGoodsInfoList.aspx?KeyStr=a4142c6da5bf47019181f54c299606b0'onclick='javascript:SetSpan1("商品设置 >> 商品列表");' target='contentiframe' id='a3'>商品列表</a>
</li>