Skip to main content
 首页 » 编程设计

c#之如何在 C# 中使用正则表达式查找以特定单词开头的 HTML 属性

2024年05月10日39zfyouxi

<分区>

我有 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); 
}