请教一个正则表达式相关的问题

sdyqingdao 2010-02-01 11:30:48
我想提取Google search结果,查看源代码我发现Google 搜索结果有以下格式:
<h3 class=r><a href="*******" class=l 。。。。。。)">********</a></h3>
请问如何用正则表达式把两处******提取出来?
...全文
112 8 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
sdyqingdao 2010-02-01
  • 打赏
  • 举报
回复
能有人帮忙写一个吗?
怒海争锋 2010-02-01
  • 打赏
  • 举报
回复
up
mbh0210 2010-02-01
  • 打赏
  • 举报
回复

(?is)<a[^>]*?href=["'\s]*(?<href>[^"]*)[^>]*>(?<Value>.*?(?=</a>))


取href和Value即可
phoeni_xin 2010-02-01
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 lcl_data 的回复:]
C# codeusing System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Text.RegularExpressions;namespace CSharpTest
{class Program
{staticvoid Main(string[] args)
{string str=@"<h3 class=r> <a href=""******111*"" class=l 。。。。。。)"">****222**** </a> </h3>";
Regex re=new Regex(@".*?href=""(?<href>[^""]*)""[^>]*>(?<title>[^<]*).*?");
Console.WriteLine("{0} {1}", re.Match(str).Groups["href"].Value, re.Match(str).Groups["title"].Value);
}
}
}
[/Quote]
mengfanzongfox 2010-02-01
  • 打赏
  • 举报
回复
up
十八道胡同 2010-02-01
  • 打赏
  • 举报
回复
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace CSharpTest
{
class Program
{
static void Main(string[] args)
{
string str=@"<h3 class=r> <a href=""******111*"" class=l 。。。。。。)"">****222**** </a> </h3> ";
Regex re = new Regex(@".*?href=""(?<href>[^""]*)""[^>]*>(?<title>[^<]*).*?");
Console.WriteLine("{0} {1}", re.Match(str).Groups["href"].Value, re.Match(str).Groups["title"].Value);
}
}
}
lovexilove 2010-02-01
  • 打赏
  • 举报
回复
up
波导终结者 2010-02-01
  • 打赏
  • 举报
回复
(?<=\<a href=")[^"]*(?=")
(?<=\>)[^\<\>]*(?=\</a\>)

111,097

社区成员

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

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

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