string str = @"(? <= <img[^>]+src="")[^""]+"; 
        Regex r = new Regex(str, RegexOptions.IgnoreCase); 
        Match m = r.Match("html代码"); 
        while (m.Success) 
        { 
            s.Add(m.Value.ToString()); 
            m = m.NextMatch(); 
        } 为什么提示正在分析“(? <= <img[^>]+src=")[^"]+)”- 无法识别的分组构造。参数名: (? <= <img[^>]+src=")[^"]+) 如何解决。难道是正则式有问题。??

解决方案 »

  1.   

    string str = @"(?<=<img[^>]+src="")[^""]+";
      

  2.   

    string str = @"(?<= <img[^>]+src="")[^""]+"; 
            Regex r = new Regex(str, RegexOptions.IgnoreCase); 
            Match m = r.Match("html代码"); 
            while (m.Success) 
            { 
                s.Add(m.Value.ToString()); 
                m = m.NextMatch(); 
            } 
      

  3.   

    <(?!img)[\s\S]*?><(\/\s*)?!?((\w+:)?\w+)(\w+(\s*=?\s*(([""'])(\\[""'tbnr]|[^\7])*?\7|\w+)|.{0})|\s)*?(\/\s*)?>
      

  4.   


    string HTML = sr.ReadToEnd();
                        sr.Close();
                        stream.Close();
                        string pattern = @"http:\/\/[^\'\""]*\.jpg";
                        Regex reg=new Regex (pattern);
                        bool result = true;
                        if (reg.IsMatch(HTML))
                        {
                            foreach (System.Text.RegularExpressions.Match m in reg.Matches(HTML))
                            {                            
                                if (result)
                                {
                                    string returnValue = DownloadImage(m.Value.ToString(),resourceId);
                                    if (returnValue == "false")
                                    { }
                                    else
                                    {
                                        result = false;
                                    }
                                }
                            }
                        }
    ................
      

  5.   

    <img[\s\S\.]*?src=[\"|'](?<groupName>\.*?["|'])匹配里找组“groupName” 内容就可以了
      

  6.   

                string str = "<img src=\"../Images/headerApplicationLogo.png\" />";
                string parent = "<img[\\s\\S]*?src=[\"|'](?<groupName>.*?[\"|'])";
                System.Text.RegularExpressions.Regex r = new System.Text.RegularExpressions.Regex(parent);
                
                foreach(System.Text.RegularExpressions.Match match  in  r.Matches(str))
                {
                  string matchvalue =  match.Groups["groupName"].Value;
                }