<IMG alt="" src=" http://localhost:31453/sehr.web/system_dntb/upload/粉刷梦想1280x800_001.jpg" width=1280 height=800>11111<IMG alt="" src=" http://localhost:31453/sehr.web/system_dntb/upload/粉刷梦想1280x800_001.jpg" width=1280 height=800>我想得到所有的#]<IMG alt="" src=" http://localhost:31453/sehr.web/system_dntb/upload/粉刷梦想1280x800_001.jpg" width=1280 height=800>这个的<IMG>节点
正则应该怎么写呢

解决方案 »

  1.   

      就是获取所有的  <IMG  ...> 这个集合、
      

  2.   

    jquery也找得到的,不一定正则
      

  3.   


    void Main()
    {
       string html=@"<IMG alt="""" src="" http://localhost:31453/sehr.web/system_dntb/upload/粉刷梦想1280x800_001.jpg"" width=1280 height=800>11111<IMG alt="""" src="" http://localhost:31453/sehr.web/system_dntb/upload/粉刷梦想1280x800_001.jpg"" width=1280 height=800>"; foreach(Match m in  Regex.Matches(html,@"(?is)<img[^>]*>"))
    {
      Console.WriteLine(m.Value);
    }
    }/*
    <IMG alt="" src=" http://localhost:31453/sehr.web/system_dntb/upload/粉刷梦想1280x800_001.jpg" width=1280 height=800>
    <IMG alt="" src=" http://localhost:31453/sehr.web/system_dntb/upload/粉刷梦想1280x800_001.jpg" width=1280 height=800>
    */
      

  4.   

    虽然大多数情况楼上的写法没错,但,最好这么写
    (?is)<img\b[^>]*>
    否则纯文本中:
    "<img标签表示图片,需要/>结尾"
    也被匹配了
      

  5.   


    void Main()
    {
       string html=@"<IMG alt="""" src="" http://localhost:31453/sehr.web/system_dntb/upload/粉刷梦想1280x800_001.jpg"" width=1280 height=800>11111<IMG alt="""" src="" http://localhost:31453/sehr.web/system_dntb/upload/粉刷梦想1280x800_001.jpg"" width=1280 height=800>"; foreach(Match m in  Regex.Matches(html,@"(?is)<img[^>]*src=(['""]?)(?<src>[^'""]+)\1[^>]*width=(?<width>\d+)[^>]*height=(?<height>\d+)[^>]*>"))
    {
      Console.WriteLine("src= "+m.Groups["src"].Value);
      Console.WriteLine("width= "+m.Groups["width"].Value);
      Console.WriteLine("height= "+m.Groups["height"].Value);
    }
    }/*
    src=  http://localhost:31453/sehr.web/system_dntb/upload/粉刷梦想1280x800_001.jpg
    width= 1280
    height= 800
    src=  http://localhost:31453/sehr.web/system_dntb/upload/粉刷梦想1280x800_001.jpg
    width= 1280
    height= 800
    */
      

  6.   

    alt=("[^"]*")\s+src=("[^"]*")\s+width=1280\s+height=800