c# 正则表达式取链接 怎么写?

weini20 2012-04-12 04:24:30

<A href='http://111.222.333' target=_blabk>固定文字</a>

字符串 是一个网页,我想把 <A href='http://111.222.333' target=_blabk>固定文字</a> 这个取出来改怎么写呢?

其中 http://111.222.333 不是固定的。后面的//固定文字 是固定的。这样的表达式应该怎么写呢?

...全文
53 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
EnForGrass 2012-04-12
  • 打赏
  • 举报
回复

string tempstr = @"<A href='http://111.222.333' target=_blabk>固定文字</a>";
string pat = @"(?is)<A\s*href='([^']*?)'\s*target=_blabk>(.*?)</a>";
MatchCollection matches = Regex.Matches(tempstr, pat);
List<string> topdata = new List<string>();
foreach (Match match in matches)
{
topdata.Add(match.Groups[1].Value, match.Groups[2].Value);//http://111.222.333,固定文字
}
我爱小土豆 2012-04-12
  • 打赏
  • 举报
回复
等着多累,,,,自己百度。。。然后搞定
bdmh 2012-04-12
  • 打赏
  • 举报
回复
Regex reg = new Regex(@"<A[^>]*?href=.*固定文字</a>");

110,499

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧