62,025
社区成员
发帖
与我相关
我的任务
分享
htmlSource = Regex.Replace(htmlSource, @"(?is)(?<=<\w+.*?)alt=['""]?[^'"">\s]*['""]?", "");
/*应对alt="" 的情况
但是当style="border:1px solid #ccc" 中含有空格的时候 和这种情况
<a target=parent href="">test </a> 会出现问题*/
//因为style这种里面可能出现空格的 其前后必定会出现单双引号 所以可以这样
htmlSource = Regex.Replace(htmlSource, @"(?is)(?<=<\w+.*?)style=(['""])[^'"">]*\1", "");
或者将标签的熟悉性都加上单引号或者双引号在处理就可以了
htmlSource = Regex.Replace(htmlSource, @"(?is)(?<=<\w+.*?)alt=['""]?[^'"">\s]+['""]?", "", RegexOptions.IgnoreCase);
// 删除rel
htmlSource = Regex.Replace(htmlSource, @"(?is)(?<=<\w+.*?)rel=['""]?[^'"">\s]+['""]?", "", RegexOptions.IgnoreCase);
htmlSource = Regex.Replace(htmlSource, @"(?is)(?<=<\w+.*?)style=.*?(?=\s\b\w+=|/?>)","");
//这样吧 你可以试一下以前的可不可以!!
Regex.Replace(input,@"(?is)(?<=<\w+.*?)target=['""]?[^'"">\s]+['""]?","");
string str = "<a href=\"\" target=\"_blank\">test</a>";
string result = Regex.Replace(str, @"<a.+href=""[^""]*([^>]*)>(.+)</a>", "<a href=\"\">$2</a>");
Console.WriteLine(result);