0

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.

2
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by agent154
0
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();
        }
0

That worked, thanks. Apparantly just needed the () around the extention.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.