基本规格:
publicliststringmatchhtmlimgsrc (string html ) ) regeximgreg=newregex )、RegexOptions.IgnoreCase ); varimgs=imgreg.Matches(html ); regexsrcreg=new regex (src=['| " ]s ['" ],RegexOptions.IgnoreCase ); Liststring links=new Liststring (; Foreach(varimginimgs ) links.add ) srcreg.match ) img.ToString ) ).tostring ).replace ) ' src=',''').} )使用方法:
liststringimglinks=matchhtmlimgsrc (' img src='图像链接1'/img src='图像链接2'/' );
一个真实razor实例:
@ using system.text.regular expressions @ { layout='~~/views/shared/_ ask.cs html '; datatabletypedt=newb _ grade option (.getgradelist ) ) 2,0 ); 数据解决方案=(数据解决方案) ViewBag.solveDt; DataTable hotDt=(DataTable ) ViewBag.hotDt; //最近20起案件为fqdxmylastaskdt=ask bll.selpage (1,20,new Com_Filter ) }.dt; } @ functions { publicliststringmatchtmlimgsrc (string html ) regeximgreg=newregex('img[^]* ',regex options.ign nonon regexsrcreg=new regex (src=['| " ]s ['" ],RegexOptions.IgnoreCase ); Liststring links=new Liststring (; Foreach(varimginimgs ) links.add ) srcreg.match ) img.ToString ) ).tostring ).replace ) ' src=',''').} }……} div class=' qitem _ pic ' @ foreach (variteminmatchtmlimgsrc (dr (' q content ' ).tostring ) ) /这是引用的行id=@