本帖最后由 5653325 于 2013-12-20 17:33:16 编辑

解决方案 »

  1.   

    我就想把各个img分组提取出来 title src 和longdesc
    这个正则写的有问题,总是只能匹配出来一条。
      

  2.   

    这样?<img[^>]*title=\\"(?<title>[^"]*)\\"[^>]*src=\\"(?<src>[^"]*)\\"
      

  3.   


    string pattern = "<img.*?title=\"(?<Title>.+?)\".*?src=\"(?<SRC>.+?)\".*?longdesc=\"(?<DESC>.+?)\" />";
    应该是 .*?  
      

  4.   

    貌似还是匹配一条(但是是错的,开头是开头,尾部是最后一个img的尾部了。)。
      

  5.   

    貌似还是匹配一条(但是是错的,开头是开头,尾部是最后一个img的尾部了。)。string sss = "<img width=\"499\" height=\"323\" title=\"asdfsadfasdf\" alt=\"\" src=\"http://images.xxxxxx.cn/2013/0522/20130522113854351.jpg\" border=\"0\" longdesc=\"asdfasdfsadfasdf\" /><img width=\"499\" height=\"323\" title=\"asdfsadfasdf\" alt=\"\" src=\"http://images.xxxxxx.cn/2013/0522/20130522113854351.jpg\" border=\"0\" longdesc=\"asdfasdfsadfasdf\" /><img width=\"499\" height=\"323\" title=\"asdfsadfasdf\" alt=\"\" src=\"http://images.xxxxxx.cn/2013/0522/20130522113854351.jpg\" border=\"0\" longdesc=\"asdfasdfsadfasdf\" /><img width=\"499\" height=\"323\" title=\"asdfsadfasdf\" alt=\"\" src=\"http://images.xxxxxx.cn/2013/0522/20130522113854351.jpg\" border=\"0\" longdesc=\"asdfasdfsadfasdf\" /><img width=\"499\" height=\"323\" title=\"asdfsadfasdf\" alt=\"\" src=\"http://images.xxxxxx.cn/2013/0522/20130522113854351.jpg\" border=\"0\" longdesc=\"asdfasdfsadfasdf\" />";            string pattern = @"<img[^>]*title=\""(?<title>[^""]*)\""[^>]*src=\""(?<src>[^""]*)\""[^>]*longdesc=\""(?<longdesc>[^""]*)";
                string title = string.Empty;
                string src = string.Empty;
                string longdesc = string.Empty;
                StringBuilder js = new StringBuilder();            Regex rr = new Regex(pattern, RegexOptions.IgnoreCase);
                MatchCollection matches = rr.Matches(sss);
                int i = 1;
                foreach (Match match in matches)
                {
                    title = match.Groups["Title"].Value;
                    src = match.Groups["SRC"].Value;
                    longdesc = match.Groups["DESC"].Value;                js.Append("<li>");
                    js.Append("<a href=\"javascript:void(0);\">");
                    js.Append("<img src=\"\" width=\"120\" height=\"80\" alt=\"" + title + "\" />");
                    js.Append("</a>");
                    js.Append("</li>");
                    i++;
                } 我这里是可以的