I'm trying to figure out why the regexp "[A-Za-z0-9\-]+\.jpg|jpeg|gif|png" only seems to find "gif" when I run it on the source of an html file..

For example: I have the following code

string URL = "http://www.google.ca";
            string re = @"[A-Za-z0-9\-]+\.jpg|jpeg|gif|png";

            WebClient wc = new WebClient();
            Stream data = wc.OpenRead(URL);
            StreamReader sr = new StreamReader(data);
            string s = sr.ReadToEnd();

            Match match = Regex.Match(s, re, RegexOptions.IgnoreCase);
            Console.WriteLine(match.ToString());

and all that outputs is "gif". I'm trying to get it to print the full filename of the image that it finds.

string re = @"[A-Za-z0-9\-]+\.(jpg|jpeg|gif|bmp)";
        Match match = Regex.Match(s, re, RegexOptions.IgnoreCase);
        while (match.Success)
        {
            Console.WriteLine(match.ToString());
            match=match.NextMatch();
        }
This question has already been answered. Start a new discussion instead.