Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6154969
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T20:21:04+00:00 2026-05-23T20:21:04+00:00

When using Sanitizer.GetSafeHtmlFragment from Microsoft’s AntiXSSLibrary 4.0, I noticed it changes my HTML fragment

  • 0

When using Sanitizer.GetSafeHtmlFragment from Microsoft’s AntiXSSLibrary 4.0, I noticed it changes my HTML fragment from:

<pre class="brush: csharp">
</pre>

to:

<pre class="x_brush: x_csharp">
</pre>

Sadly their API doesn’t allow us to disable this behavior. Therefore I’d like to use a regular expression (C#) to fix and replace strings like “x_anything” to “anything”, that occur inside a class=”” attribute.

Can anyone help me with the RegEx to do this?

Thanks

UPDATE – this worked for me:

 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;
        }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T20:21:07+00:00Added an answer on May 23, 2026 at 8:21 pm

    Im not 100% sure about the C# @(Verbatim symbol) but I think this should match x_ inside of any class="" and replace it with an empty string:

    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,"");
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently using the Microsoft AntiXSS library and using the GetSafeHtmlFragment method as
I'm using an HTML sanitizing whitelist code found here: http://refactormycode.com/codes/333-sanitize-html I needed to add
I'm pulling content from a DB that has been sanitized using mysql_real_escape_string. Accordingly the
I recently was using HttpWebResponse to return xml data from a HttpWebRequest, and I
Using the Sanitize gem, I'm cleaning some HTML. In the href attribute of my
I'm working with Ruby on Rails, Is there a way to strip html from
I'm using HTML Purifier , a PHP filter that guards against XSS and ensures
I'm attempting to use jsoup to sanitize the the html posted from a wysiwyg
I'm trying to sanitize/format some input using regex for a mixed latin/ideographic(chinese/japanse/korean) full text
I am using codeigniter framework. where should i sanitize PHP input - controller or

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.