Regex is not a good for parsing HTML files.HTML is not strict nor is it regular with its format.(for example: in non strict html its OK to have a tag without a closing tag)
Use htmlagilitypack
You can use htmlagilitypack
to do it like this
HtmlDocument doc = new HtmlDocument();
doc.Load(yourStream);
foreach(var item in doc.DocumentNode.SelectNodes("//img[@src]"))//select only those img that have a src attribute..ahh not required to do [@src] i guess
{
item.Attributes["src"].Value=yourFunction(item.Attributes["src"].Value);
}
doc.Save("yourFile");//dont forget to save