求一个正则表达式

yuankunliuying 2010-09-29 12:31:10
页面源码中存在
<a href="/market/detail/006001/2010-09-27/3443.html" >

要找出类似的href把关于 /market/detail/的链接都找出来。
...全文
86 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
-过客- 2010-09-29
  • 打赏
  • 举报
回复
try...

Regex reg = new Regex(@"(?i)<a[^>]*?href=(['""]?)(?<url>/market/detail/[^'""\s>]+)\1[^>]*>");
MatchCollection mc = reg.Matches(yourStr);
foreach (Match m in mc)
{
richTextBox2.Text += m.Groups["url"].Value + "\n";
}
兔子-顾问 2010-09-29
  • 打赏
  • 举报
回复
少转义了。
MatchCollection mc = Regex.Matches(html字符串,@"<a href=""/market/detail/[^>]*>");
foreach(Match m in mc)
{
//m.Value就是你要的每一个类似的标记
}
wuyq11 2010-09-29
  • 打赏
  • 举报
回复
Regex reg = new Regex(@"(?i)<a[^>]*?href=(['""]?)(?<url>[^'""\s>]+)\1[^>]*>");
MatchCollection mc = reg.Matches("");
foreach (Match m in mc)
{
richTextBox2.Text += m.Groups["url"].Value + "\n";
}
兔子-顾问 2010-09-29
  • 打赏
  • 举报
回复
MatchCollection mc = Regex.Matches(html字符串,@"<a href="/market/detail/[^>]*>");
foreach(Match m in mc)
{
//m.Value就是你要的每一个类似的标记
}
yuankunliuying 2010-09-29
  • 打赏
  • 举报
回复

顶上来
yuankunliuying 2010-09-29
  • 打赏
  • 举报
回复
谢谢大家哈
路人乙e 2010-09-29
  • 打赏
  • 举报
回复
string str = "<a href='/market/detail/23974/aaa.html'></a>lkj<a href='/market/detail/23974/bbb.html'></a>";
Regex.Replace(str, @"(?i)href=(['""]{0,1})(/market/detail/[^\1]+?)\1",
new MatchEvaluator(delegate(Match m){
Console.WriteLine(m.Groups[2].Value);return "";
}));

111,129

社区成员

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

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

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