格式如这样的:<img src="http://A/B/C"  border="1" align="left" class="student" /></a>
想取到值C,其中A和B是固定的,就向时http://www.123.com/files/1.jpg,那么A就是http://www.123.com/,B就是files,c酒是1.jpg,也就是我想要的,请问这个正则怎么写,谢了!

解决方案 »

  1.   

                    string str = "<img src=\"http://www.123.com/files/1.jpg\" border=\"1\" align=\"left\" class=\"student\" /></a>";
                    Regex reg = new Regex(@"(?is)<img[^>]*?src=(['""\s]?)http://www.123.com/files/([^'""\s]+)\1[^>]*?>");
                    foreach (Match m in reg.Matches(str))
                        Console.WriteLine(m.Groups[2].Value);
      

  2.   


                    string src = @"<img src=""http://www.123.com/files/1.jpg"" border=""1"" align=""left"" class=""student"" /><img src=""http://www.123.com/files/2.jpg"" border=""1"" align=""left"" class=""student"" />";
                    Regex re = new Regex(@"src=""(?<http>[^""]+?)/(?<f2>[^/]+?)/(?<f3>[^/]+?)""", RegexOptions.IgnoreCase);
                    Match mc = re.Match(src);
                    while( mc.Success)
                    {
                        Response.Write(mc.Groups["http"]);
                        Response.Write("<br/>");
                        Response.Write(mc.Groups["f2"]);
                        Response.Write("<br/>");
                        Response.Write(mc.Groups["f3"]);
                        Response.Write("<br/>*************************<br/>");
                        mc = mc.NextMatch();
                       
                    }
                    Response.End();
      

  3.   

    简单点:<img.*www\.123\.com\/files\/(\w+\.\w+)