Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get all Images src's of some html

Tags:

c#

regex

image

I use this

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

to get an images src.

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

Thanks!

like image 791
Friend Avatar asked Dec 17 '22 00:12

Friend


1 Answers

You should use Regex.Matches instead of Match, and you should add the Multiline option I believe:

foreach (Match m in Regex.Matches(sometext, "<img.+?src=[\"'](.+?)[\"'].+?>", RegexOptions.IgnoreCase | RegexOptions.Multiline))
{
    string src = m.Groups[1].Value;
    // add src to some array
}
like image 186
urraka Avatar answered Dec 28 '22 11:12

urraka