日期:2014-05-18  浏览次数:20523 次

求一正则,匹配出源码中的所有图片
假设源码如下
http://www.csdn.net/dsalkdsalkkladlskdjklj http://1.1.com/jpg.jpgjpgasdasdasdasdshttp://3.2.com/gif.gifgiff2i3olk

匹配出
http://1.1.com/jpg.jpg
http://3.2.com/gif.gif

------解决方案--------------------
C# code
Regex re = new Regex("(?<=^(http://.*))http://.*?(\\.jpg|\\.gif)", RegexOptions.None);

------解决方案--------------------
C# code
 string tempStr = "http://www.csdn.net/dsalkdsalkkladlskdjklj http://1.1.com/jpg.jpgjpgasdasdasdasdshttp://3.2.com/gif.gifgiff2i3olk";
                string pattern = @"(?i)http://\S+?\.(jpg|gif|jepg|png|bmp)";
                foreach (Match m in Regex.Matches(tempStr, pattern))
                {
                    //循环输出
                    string value = m.Value;
                    /*
                     * http://1.1.com/jpg.jpg
                     * http://3.2.com/gif.gif
                     */

                }