", RegexOptions...">

How to get all src images from some html

I use this

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

to get src images.

But how do I get all src that I can find?

Thank!

+3
source share
1 answer

You should use Regex.Matches instead of Match, and you should add the Multiline parameter, which I consider:

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

All Articles