RegularExpresion(快速提问) [英] RegularExpresion (fast question)

查看:62
本文介绍了RegularExpresion(快速提问)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨.我无法获得RegEx结果.因此,这里有一段代码简述了我所做的事情.此代码与我无法正常工作的项目完全相同. :)

代码:

Hi. I can''t get my RegEx results. So here''s a little code snipet what I have made. This code is exact the same like in my not working project. :)

Code:

   string url = string.Format("http://www.google.lv/search?hl=lv&q=roze%23&bav=on.2,or.r_gc.r_pw.&um=1&ie=UTF-8&tbm=isch&source=og&sa=N&tab=wi&sout=1&biw=1280&bih=651");
   WebClient wb = new WebClient();
   string content = wb.DownloadString(url);

   Regex reg = new Regex(@"imgres\?imgurl.*?(,""){5}");

   MatchCollection mm = reg.Matches(content);

   foreach (Match item in mm)
   {
       Console.WriteLine(item.ToString());
   }
Console.ReadLine();


我下载了Google图片页面内容.我使用RegEx为将来的活动获取一些字符串.但这只是行不通.我在"RegExBuilder"应用程序中构建此reg.并显示21场比赛.
在VS 2010中->没有比赛! :)
谁能告诉我->为什么不起作用?
谢谢!

P.S.在我的时区是1:20.我会在早上回答:)


I download google image page content. I use RegEx to get some string for my future activitys. But it just don''t work. This reg I build in "RegExBuilder" app. and it showes me 21 match.
In VS 2010 -> No match! :)
So can anyone tell me -> Why it doesn''t work?
Thanks!

P.S. In my time zone it is 1:20. I will answer in morning :)

推荐答案

//Get related text block
string subContent = Regex.Match(content,@"(?<=dyn.setResults\(\[).*?(?=\]\);)").Value;
// Get rid of empty lists
subContent = subContent.Replace("[],", "");
// Get list of images
MatchCollection mc = Regex.Matches(subContent , @"(?<=\[).*?(?=\])");
// Now mc holds your 21 results
foreach(System.Text.RegularExpressions.Match m in mc)
{
    // Split parameters of dyn.setResults
    string[] args = m.Value.Split(',');
    // 4th value of args hold your image url
}


相当脏,但是希望对您有所帮助.


Quite dirty but, hope it helps.


这篇关于RegularExpresion(快速提问)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆