在使用MicrosoftHTML4.0中的Sanitizer.GetSafeHtmlFragment时,我注意到它从以下几个方面更改了我的AntiXSSLibrary片段:
<pre class="brush: csharp">
</pre>至:
<pre class="x_brush: x_csharp">
</pre>可悲的是,他们的API不允许我们禁用这种行为。因此,我想使用正则表达式(C#)来修复和替换出现在class="“属性中的字符串,比如"x_anything”。
有人能帮我做RegEx吗?
谢谢
UPDATE --这对我有用:
private string FixGetSafeHtmlFragment(string html)
{
string input = html;
Match match = Regex.Match(input, "class=\"(x_).+\"", RegexOptions.IgnoreCase);
if (match.Success)
{
string key = match.Groups[1].Value;
return input.Replace(key, "");
}
return html;
}发布于 2011-07-18 19:20:00
Im对C# @(逐字符号)不是百分之百肯定,但我认为这应该与任何class=""中的x_匹配,并用空字符串替换它:
string input = 'class="x_something"';
Match match = Regex.Match(input, @'class="(x_).+"',
RegexOptions.IgnoreCase);
if (match.Success)
{
string key = match.Groups[1].Value;
string v = input.Replace(key,"");
}发布于 2012-11-17 09:34:10
这篇文章已经发布了一年多了,但是这里有一些正则表达式,您可以使用它来删除最多三个类实例。我相信有一个更清洁的方法,但它可以完成工作。
VB.Net代码:
Regex.Replace(myHtml, "(<\w+\b[^>]*?\b)(class="")x[_]([a-zA-Z]*)( )?(?:x[_])?([a-zA-Z]*)?( )?(?:x[_])?([^""]*"")", "$1$2$3$4$5$6$7")https://stackoverflow.com/questions/6737997
复制相似问题