public static string RemoveAllAttributesWithoutSrc(string input)
{
string pattern = @"<([a-z][a-z0-9]*)(?:[^>]*(\ssrc=[‘\""][^‘\""]*[‘\""]))?[^>]*?(\/?)>";
var result = Regex.Replace(input, pattern, "<$1$2$3>");
return result;
}
[TestMethod]
public void TestMethod1()
{
var input = @" <a style=‘asdfasdfasdfasdfasdf‘ class=""afasdfasdfasdfasdf"" /> <img src=‘www.abc.com/jpg/dd‘ />";
string pattern = @"<([a-z][a-z0-9]*)(?:[^>]*(\ssrc=[‘\""][^‘\""]*[‘\""]))?[^>]*?(\/?)>";
var result = Regex.Replace(input, pattern, "<$1$2$3>");
Console.WriteLine (result);
}
PHP:http://stackoverflow.com/questions/2994448/regex-strip-html-attributes-except-src