c# - extract multiple query params with regex -


i've been thinking day , need helt solve it.

i've got html below , wants extract values of query parameter matching "?imgurl=". can me out regex this?

</script></div><div id=nr_container><div id=center_col><div id=tbbcc><div id=tbbc style="background:#ebeff9;margin-bottom:4px;padding:8px;display:none"></div></div><div id=res class=med role=main><div id=topstuff></div><!--a--><h2 class=hd>søgeresultater</h2><div id=ires><ol><script>google.isr.fillcanvas=function(i){var c=document.getelementbyid('cvs_'+i.id);try{c&&(c.getcontext('2d').drawimage(i,0,0,c.offsetwidth,c.offsetheight));}catch(e){c.style.display='none';i.style.display='block';}}</script><div id=rgsh_s></div><li><div id=rg><div id=rg_s><div id=rg_hp><a id=rg_hpl></a></div><div class=rg_h id=rg_h><div class=rg_hc><a class=rg_hl id=rg_hl><img class=rg_hi id=rg_hi></a><div class=std id=rg_hx><p class=rg_ht id=rg_ht><a id=rg_hta></a></p><p class=rg_hn id=rg_hn></p><p class=rg_hr><span id=rg_hr></span></p><p class=rg_ha><span id=rg_ha><a class=rg_hal id=rg_hals></a><span id=rg_has>&nbsp;&#8209;&nbsp;</span><a class=rg_hal id=rg_haln></a><span id=rg_has2>&nbsp;&#8209;&nbsp;</span><a class=rg_hal id=rg_halm></a></span></p></div></div></div><span class=rg_ctlv><ul class=rg_ul data-pg=1 data-cnt=44><li class=rg_li data-row=1 style="width:193px;height:145px" ><a class=rg_l style="width:193px;height:145px;margin-top:0px;margin-left:0px" href="/imgres?imgurl=http://www.eecs.berkeley.edu/~loarie/test.colors.gif&amp;imgrefurl=http://s1mon.smartlog.dk/test-post37556&amp;usg=__xdes-qa3w9np6dmnds0hpte2bn8=&amp;h=606&amp;w=807&amp;sz=18&amp;hl=da&amp;start=1&amp;zoom=1&amp;tbnid=sfzpf2rpdevhlm:&amp;tbnh=107&amp;tbnw=143&amp;ei=q9k-tylkeob0swozpdh0ba&amp;prev=/images%3fq%3dtest%26hl%3dda%26safe%3doff%26sa%3dg%26as_st%3dy%26biw%3d1680%26bih%3d897%26tbs%3disch:1&amp;itbs=1"><script>google.stb.csi.sttbn()</script><canvas id="cvs_sfzpf2rpdevhlm:l" style="display:block" width=193 height=145></canvas><img class=rg_i id=sfzpf2rpdevhlm:l height=145 width=193 style="width:193px;height:145px" onload="google.isr.fillcanvas(this);google.stb.csi.ontbn(1, this)"></a></li><li class=rg_li style="width:154px;height:145px" ><a class=rg_l style="width:160px;height:145px;margin-top:0px;margin-left:-2px" href="/imgres?imgurl=http://www.krymmel.dk/dev/media/.jkforum/test-pilot.png&amp;imgrefurl=http://www.krymmel.dk/dev/pages/forum.php&amp;usg=__a-kjqidnkky8lxlcv-d3xzpkguw=&amp;h=327&amp;w=360&amp;sz=110&amp;hl=da&amp;start=2&amp;zoom=1&amp;tbnid=klm4rocmahp8wm:&amp;tbnh=110&amp;tbnw=121&amp;ei=q9k-tylkeob0swozpdh0ba&amp;prev=/images%3fq%3dtest%26hl%3dda%26safe%3doff%26sa%3dg%26as_st%3dy%26biw%3d1680%26bih%3d897%26tbs%3disch:1&amp;itbs=1"><script>google.stb.csi.sttbn()</script><canvas id="cvs_klm4rocmahp8wm:l" style="display:block" width=160 height=145></canvas><img class=rg_i id=klm4rocmahp8wm:l height=145 width=160 style="width:160px;height:145px" onload="google.isr.fillcanvas(this);google.stb.csi.ontbn(1, this)"></a></li><li class=rg_li style="width:148px;height:145px" ><a class=rg_l style="width:148px;height:145px;margin-top:0px;margin-left:0px" href="/imgres?imgurl=http://colorvisiontesting.com/plate%2520with%25205.jpg&amp;imgrefurl=http://colorvisiontesting.com/ishihara.htm&amp;usg=__ufbi8sd8ldljjik3-7agjo0zky4=&amp;h=309&amp;w=315&amp;sz=142&amp;hl=da&amp;start=3&amp;zoom=1&amp;tbnid=2_umdol8aqhejm:&amp;tbnh=115&amp;tbnw=117&amp;ei=q9k-tylkeob0swozpdh0ba&amp;prev=/images%3fq%3dtest%26hl%3dda%26safe%3doff%26sa%3dg%26as_st%3dy%26biw%3d1680%26bih%3d897%26tbs%3disch:1&amp;itbs=1"><script>google.stb.csi.sttbn()</script><canvas id="cvs_2_umdol8aqhejm:l" style="display:block" width=148 height=145></canvas><img class=rg_i id=2_umdol8aqhejm:l height=145 width=148 style="width:148px;height:145px" onload="google.isr.fillcanvas(this);google.stb.csi.ontbn(1, this)"></a></li><li class=rg_li style="width:193px;height:145px" ><a class=rg_l style="width:193px;height:145px;margin-top:0px;margin-left:0px" href="/imgres?imgurl=http://pun.org/josh/archives/04.10.01.globaltest-x.gif&amp;imgrefurl=http://hovedstaden.inetgiant.dk/fredensborg/addetails/test/3187460&amp;usg=___4p_udkemuovxcijq-py9whg1vw=&amp;h=391&amp;w=520&amp;sz=44&amp;hl=da&amp;start=4&amp;zoom=1&amp;tbnid=l15zkno3p4iycm:&amp;tbnh=99&amp;tbnw=131&amp;ei=q9k-tylkeob0swozpdh0ba&amp;prev=/images%3fq%3dtest%26hl%3dda%26safe%3doff%26sa%3dg%26as_st%3dy%26biw%3d1680%26bih%3d897%26tbs%3disch:1&amp;itbs=1"><script>google.stb.csi.sttbn()</script><canvas id="cvs_l15zkno3p4iycm:l" style="display:block" width=193 height=145></canvas><img class=rg_i id=l15zkno3p4iycm:l height=145 width=193 style="width:193px;height:145px" onload="google.isr.fillcanvas(this);google.stb.csi.ontbn(1, this)"></a></li><li class=rg_li style="width:193px;height:145px" ><a class=rg_l style="width:193px;height:139px;margin-top:3px;margin-left:0px" href="/imgres?imgurl=http://www.daimi.au.dk/~rvinge/test_daimi.jpg&amp;imgrefurl=http://www.daimi.au.dk/~rvinge/hot.list.html&amp;usg=__ofrc4g4fpzgxi95enpnig4wpdlg=&amp;h=881&amp;w=1223&amp;sz=228&amp;hl=da&amp;start=5&amp;zoom=1&amp;tbnid=wdreipjckhg13m:&amp;tbnh=108&amp;tbnw=150&amp;ei=q9k-tylkeob0swozpdh0ba&amp;prev=/images%3fq%3dtest%26hl%3dda%26safe%3doff%26sa%3dg%26as_st%3dy%26biw%3d1680%26bih%3d897%26tbs%3disch:1&amp;itbs=1"><script>google.stb.csi.sttbn()</script><canvas id="cvs_wdreipjckhg13m:l" style="display:block" width=193 height=139></canvas><img class=rg_i id=wdreipjckhg13m:l height=139 width=193 style="width:193px;height:139px" onload="google.isr.fillcanvas(this);google.stb.csi.ontbn(1, this)"></a></li><li class=rg_li style="width:143px;height:145px" ><a class=rg_l style="width:145px;height:145px;margin-top:0px;margin-left:0px" href="/imgres?imgurl=http://www.textually.org/tv/archives/images/set3/test-pattern-clock_4767.jpg&amp;imgrefurl=http://hovedstaden.inetgiant.dk/fredensborg/addetails/test/3187460&amp;usg=__bfapejcst7ygne72uti6sjkxmik=&amp;h=308&amp;w=307&amp;sz=18&amp;hl=da&amp;start=6&amp;zoom=1&amp;tbnid=m1qyuhlkz-mxcm:&amp;tbnh=117&amp;tbnw=117&amp;ei=q9k-tylkeob0swozpdh0ba&amp;prev=/images%3fq%3dtest%26hl%3dda%26safe%3doff%26sa%3dg%26as_st%3dy%26biw%3d1680%26bih%3d897%26tbs%3disch:1&amp;itbs=1"><script>google.stb.csi.sttbn()</script><canvas id="cvs_m1qyuhlkz-mxcm:l" style="display:block" width=145 height=145></canvas><img class=rg_i id=m1qyuhlkz-mxcm:l height=145 width=145 style="width:145px;height:145px" onload="google.isr.fillcanvas(this);google.stb.csi.ontbn(1, this)"></a></li><li class=rg_li style="width:118px;height:145px" ><a class=rg_l style="width:118px;height:145px;margin-top:0px;margin-left:0px" href="/imgres?imgurl=http://imgs.xkcd.com/comics/turing_test.png&amp;imgrefurl=http://xkcd.com/329/&amp;usg=__ddatxocogud2ubyums_iwi4r54i=&amp;h=394&amp;w=320&amp;sz=22&amp;hl=da&amp;start=7&amp;zoom=1&amp;tbnid=ueywzfjyerem6m:&amp;tbnh=124&amp;tbnw=101&amp;ei=q9k-tylkeob0swozpdh0ba&amp;prev=/images%3fq%3dtest%26hl%3dda%26safe%3doff%26sa%3dg%26as_st%3dy%26biw%3d1680%26bih%3d897%26tbs%3disch:1&amp;itbs=1"><script>google.stb.csi.sttbn()</script><canvas id="cvs_ueywzfjyerem6m:l" style="display:block" width=118 height=145></canvas><img class=rg_i id=ueywzfjyerem6m:l height=145 width=118 style="width:118px;height:145px" onload="google.isr.fillcanvas(this);google.stb.csi.ontbn(1, this)"></a></li><li class=rg_li style="width:133px;height:145px" ><a class=rg_l style="width:149px;height:145px;margin-top:0px;margin-left:-4px" href="/imgres?imgurl=http://thomasdamgaard.dk/blog/images/test01.jpg&amp;imgrefurl=http://thomasdamgaard.dk/blog/test-skilt-pa-motorvejen&amp;usg=__quqwehgs6ofagglm5dbauetlrqu=&amp;h=487&amp;w=500&amp;sz=22&amp;hl=da&amp;start=8&amp;zoom=1&amp;tbnid=hwahmyrtavz5im:&amp;tbnh=127&amp;tbnw=130&amp;ei=q9k-tylkeob0swozpdh0ba&amp;prev=/images%3fq%3dtest%26hl%3dda%26safe%3doff%26sa%3dg%26as_st%3dy%26biw%3d1680%26bih%3d897%26tbs%3disch:1&amp;itbs=1"><script>google.stb.csi.sttbn()</script><canvas id="cvs_hwahmyrtavz5im:l" style="display:block" width=149 height=145></canvas><img class=rg_i id=hwahmyrtavz5im:l height=145 width=149 style="width:149px;height:145px" onload="google.isr.fillcanvas(this);google.stb.csi.ontbn(1, this)"></a></li><li class=rg_li style="width:100px;height:145px" ><a class=rg_l style="width:102px;height:145px;margin-top:0px;margin-left:0px" href="/imgres?imgurl=http://www.ct4me.net/images/dmbtest.gif 

it irritates me people quick jump on don't use regex parse html. you're not parsing html here anyway. if use html agility pack extract urls html, you're still going need pull imgurl parameters out of each query string.

regex perfect extracting parameters query string, , want:

string input = "your big html string"; matchcollection matches = regex.matches(     input,      @"(?<=[?&]imgurl=)[^&#'"]*",      regexoptions.ignorecase // remove if don't want ignore case in "imgurl" ); 

i'm using html agility pack parsing html, if want strip few strings (which fit defined pattern) out of bigger string, there's no better tool job regex. reason it's bad use regex parse html tags, html isn't reliably structured. url's query string has in particular format, it's safe use regex.


Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -