如何获得一些HTML的所有图像src

时间:2012-05-10 16:49:41

标签: c# regex image

我用这个

string matchString = Regex.Match(sometext, "<img.+?src=[\"'](.+?)[\"'].+?>", RegexOptions.IgnoreCase).Groups[1].Value;

获取图像src。

但是我如何才能获得所有可以找到的src?

谢谢!

1 个答案:

答案 0 :(得分:8)

你应该使用Regex.Matches而不是Match,你应该添加我相信的Multiline选项:

foreach (Match m in Regex.Matches(sometext, "<img.+?src=[\"'](.+?)[\"'].+?>", RegexOptions.IgnoreCase | RegexOptions.Multiline))
{
    string src = m.Groups[1].Value;
    // add src to some array
}