<分区> 分区>
我有 html 代码,jQuery 向它添加了随机属性,例如:
<td style='font-size: x-large;' jquery9202340423042='22423423424'>
我想使用 c# Regex 查找并删除以 jquery 开头的任何属性
我有下面的代码,但它删除了所有属性:
public static void Main(string[] args)
{
string before ="<td style='font-size: x-large;' jquery9202340423042='22423423424'>";
//string after = Regex.Replace(before, regexImgSrc, "<$1>");
//string regexImgSrc = @"<(table|tr|td)[^>]*?" + "jquery9202340423042" + @"\s*=\s*[""']?([^'"" >]+?)[ '""][^>]*?>";
string after = Regex.Replace(before, @"(?i)<(table|tr|td)(?:\s+(?:""[^""]*""|'[^']*'|[^""'>])*)?>", "<$1>");
Console.WriteLine(after);
}
