62,243
社区成员




<a href="/Portals/0/201111510304674.jpg"><img alt="" style="width: 167px; height: 242px" src="http://127.0.0.1/Portals/0/BatchImages/2013/0514/635041461750963374.jpg" /></a>
很简单的用正则就可以匹配出来
string html = @"<a href=""/Portals/0/201111510304674.jpg""><img alt="""" style=""width: 167px; height: 242px"" src=""http://127.0.0.1/Portals/0/BatchImages/2013/0514/635041461750963374.jpg"" /></a>"; string htmlpattern = @"(?is)<a[^>]*?href=""(?<href>[^""]*?)""[^>]*?>\s*<img[^>]*?src=""(?<src>[^""]*?)""[^>]*?/>\s*</a>"; Console.WriteLine(Regex.Match(html, htmlpattern).Groups["href"].Value); Console.WriteLine(Regex.Match(html, htmlpattern).Groups["src"].Value);
Regex regex = new Regex("<a.*?href=\"(?<href>.*?)\".*?src=\"(?<src>.*?)\".*?>", RegexOptions.Compiled);
string html = @"<a href=""/Portals/0/201111510304674.jpg""><img alt="""" style=""width: 167px; height: 242px"" src=""http://127.0.0.1/Portals/0/BatchImages/2013/0514/635041461750963374.jpg"" /></a>";
string htmlpattern = @"(?is)<a[^>]*?href=""(?<href>[^""]*?)""[^>]*?>\s*<img[^>]*?src=""(?<src>[^""]*?)""[^>]*?/>\s*</a>";
Console.WriteLine(Regex.Match(html, htmlpattern).Groups["href"].Value);
Console.WriteLine(Regex.Match(html, htmlpattern).Groups["src"].Value);