感觉自写的正则没错啊,可就是什么也捕获不到,代码在里面,请高手改下,谢谢!!!

Ptrtoptr 2014-09-10 08:35:58
      public static void Main(string[] args) {
//我想捕获的字串在是下面这句的里的http连接地址
//document.write("<img src='http://image.58.com/showphone.aspx?t=v55&v=E511117D78B8E33565689DD9FA350ECC0' />")
string phone =
"document.write(\"<img src='http://image.58.com/showphone.aspx?t=v55&v=E511117D78B8E33565689DD9FA350ECC0' />\")";
//下面是我写的pattern
string pattern= @"document.write(""<img\s+src='(?<url>http://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?)'\s+/>"")";
Regex r = new Regex(pattern, RegexOptions.IgnoreCase);
MatchCollection m = r.Matches(phone);
for (int i = 0; i < m.Count; i++) {
Console.WriteLine(m[i].Groups["url"].ToString());
}

Console.ReadKey(true);
}
...全文
90 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
thoughter 2014-09-10
  • 打赏
  • 举报
回复
string pattern= @"document.write\(""<img\s+src='(?<url>http://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?)'\s+/>""\)";
括号有歧义
杜子寒 2014-09-10
  • 打赏
  • 举报
回复
@"<img\b[^<>]*?\bsrc[\s\t\r\n]*=[\s\t\r\n]*[""']?[\s\t\r\n]*(?<imgUrl>[^\s\t\r\n""'<>]*)[^<>]*?/?[\s\t\r\n]*>"

110,561

社区成员

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

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

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