如题,比如下面的字符串里有两个img标签:
<img src="aa.jpg" id="img1" />
<img src="bb.jpg" class="image" shuxing="shux" />
两个标签里的属性个数未知,顺序未知,有可能还存在自己添加的属性:比如shuxing="shux"
我现在想把这字符串里所有的img标签的属性提取出来结果放在:List<Dictionary<string,string>>(List<Dictionary<属性名称,属性值>>) 里面.请大家帮帮忙,

解决方案 »

  1.   

    属性(?is)(?<=\s*?)[a-z\d]*?(?==")
    值(?is)(?<==")[a-z\d\.]*?(?=")
      

  2.   


    void Main()
    {
    string html=@"<img src=""aa.jpg"" id=""img1"" />
    <img src=""bb.jpg"" class=""image"" shuxing=""shux"" />";
        foreach(Match m in Regex.Matches(html,@"(?i)<img\s*((?<key>[^=]+)=""(?<value>[^""]+)"")+?\s*/>"))
    {
       foreach(Capture c in m.Groups["key"].Captures)
       {
         Console.WriteLine(c.Value);
       }
         Console.WriteLine("*************");
         foreach(Capture c in m.Groups["value"].Captures)
       {
         Console.WriteLine(c.Value);
       }
        Console.WriteLine("*************");
    }

    /*
    src
    id
    *************
    aa.jpg
    img1
    *************
    src
    class
    shuxing
    *************
    bb.jpg
    image
    shux
    ************* */
    }
      

  3.   

    (?i)<img\s*((?<key>[^=]+)=""(?<value>[^""]+)"")+?\s*>
    兄弟在不? 这个 还是不行  下面有3各图片,这只能找到一张。<DIV class="imgfocus yui3-tabs-panel yui3-tabs-panel-selected"><IMG title="网易新闻客户端 ipad版图片" alt=ipad src="http://img1.cache.netease.com/mobile/img/xwkhd2012/504x485c.jpg" width=504 height=485> </DIV>
    <DIV class="download-area yui3-tabs-panel yui3-tabs-panel-selected"><A class=downloadbtn title=ipad版网易新闻客户端下载 href="http://itunes.apple.com/cn/app/id425349261?mt=8" target=_self></A></DIV>
    <DIV class=tab-box-content>
    <DIV class="imgfocus yui3-tabs-panel"><IMG title="网易新闻客户端 android版图片" alt=android src="http://img1.cache.netease.com/mobile/img/xwkhd2012/androidfocus.jpg" width=504 height=485> </DIV>
    <DIV class="download-area yui3-tabs-panel"><A class=downloadbtn title=android版网易新闻客户端下载 href="http://3g.163.com/links/3040" target=_self></A></DIV></DIV>
    <DIV class=tab-box-content>
    <DIV class="imgfocus yui3-tabs-panel"><IMG title="网易新闻客户端 symbian版图片" alt=symbian src="http://img1.cache.netease.com/mobile/img/xwkhd2012/symbianfocus.jpg" width=504 height=485> </DIV>
    <DIV class="download-area yui3-tabs-panel">
    <DIV class=download-area-symbian><A class=downloadbtn-v3 title="symbian v3版网易新闻客户端下载" href="http://3g.163.com/links/3041" target=_self></A><A class=downloadbtn-v5 title="symbian v5版网易新闻客户端下载" href="http://file.ws.126.net/3g/client/netease_newsreader_s60v5.sisx" target=_self></A>
    <P></P></DIV></DIV></DIV>
    <DIV class=tab-box-content>
    <DIV class="imgfocus yui3-tabs-panel"><IMG title="网易新闻客户端 windows phone7版图片" alt="windows phone7" src="http://img1.cache.netease.com/mobile/img/xwkhd2012/W7.png" width=503 height=485> </DIV>
    <DIV class="download-area yui3-tabs-panel"><A class=downloadbtn title="windows phone7版网易新闻客户端下载" href="http://www.windowsphone.com/zh-CN/apps/83719f24-5bdb-4cbc-8e9e-066fffd2fbbe" target=_self></A></DIV></DIV>
    <DIV class=clear></DIV>
    <DIV class=focus-nav>
    <P class=summary>核心提示:近日,央视《每周质量报告》曝光9家药企的13种产品采用铬超标的胶囊。目前,只有两家药企宣布召回被曝光的胶囊产品。部分民众对胶囊药产生了恐慌,有网友甚至想出用馒头皮包药粉服用的做法。对此,有专家表示,胶囊药不要打开服用,尤其是肠溶性和缓释胶囊。</P><SPAN class=blank12></SPAN>
    <DIV id=endText>
    <P><!--图片start--><!--图片搜索--></P>
    <P><!--Yc94EUEtAn4YSUKCaSOM --></P>
    <P><!--图片搜索--      <!--图片end--><!--正文start--></P>
    <P class=f_center><IMG alt="网友用馒头替代胶囊 专家称不可以打开吞服" src="http://img1.cache.netease.com/cnews/2012/4/18/2012041808272091ec6.jpg"><BR>网友用馒头替代胶囊<BR></P>
    <P><STRONG>能剥掉胶囊直接吃药吗?</STRONG></P>
    <P>连日来,央视《每周质量报告》曝光国内9家药企的13种产品采用了铬超标的空心胶囊,在国内引起轩然大波。</P>
    <P>截至目前,只有两家药企宣布召回被曝光批次的胶囊药物,其余药企均暂无动作。</P>
    <P>“毒胶囊”成为社会关注的焦点,而公众对于胶囊药的信任度也降到了冰点。</P>
    <P><!--奥迪--></P>
    <P>记者在本地药店调查发现,虽然被曝光的“毒胶囊”已经难觅踪迹,但是患者坚决对各类胶囊药说“不”。</P>
    <P>而在网络上,一些“安全服用胶囊”的帖子却在</P>
    <P><IMG border=0 hspace=0 alt="" align=baseline src="F:\My Documents\桌面\1.jpg"></P></DIV></DIV>