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 9167979
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T15:31:19+00:00 2026-06-17T15:31:19+00:00

I was trying to filter out non-valid characters from xml. Although I have successfully

  • 0

I was trying to filter out non-valid characters from xml. Although I have successfully done it, I wrote a regex during the process that is working counter-intuitive for me.

Please consider the following .Net regex evaluation:

System.Text.RegularExpressions.Regex.Match("Test", @"[\x01-\x08\x0B-\x0C\x0E-\x1F\xD800-\xDFFF\xFFFE-\xFFFF]+").ToString()

Now my understanding is the Regex pattern matches all non-valid xml characters. According to this page:
http://www.w3.org/TR/REC-xml/#NT-Char

These are valid characters:

#x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF]

In my understanding, the regex pattern above is a set difference of remaining Unicode characters (i.e. invalid xml characters). However still running the above statement produces this result:

“Test”

(i.e. the entire input string). I am not able to understand why. In particular, this portion of the regex causes the match:
\xD800-\xDFFF

And to me it appears the same is excluded by these 2 groups from valid characters:
[#x20-#xD7FF] | [#xE000-#xFFFD]

So I am totally at loss in understanding why a match is produced by the above statement. Can somebody please help me deciphre it.

  • 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-06-17T15:31:20+00:00Added an answer on June 17, 2026 at 3:31 pm

    Try using \u instead of \x.

    System.Text.RegularExpressions.Regex.Match("Test", @"[\x01-\x08\x0B-\x0C\x0E-\x1F\uD800-\uDFFF\uFFFE-\uFFFF]+").ToString();
    

    The way I understand it is your current regex is matching the string “Test” because it is essentially matching on the following ranges

    \x01-\x08
    \x0B-\x0C
    \x0E-\x1F
    \xD8
    0
    0-\xDF
    F
    F
    \xFF
    FE-\xFF
    FF
    

    The match 0-\xDF is likely to be the pattern that matches a wide range of characters.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to filter out unwanted data from an XML file. I have
I am trying to filter out all non latin characters, such as γειά σου
I have been trying unsuccessfully to find a way to filter out records from
I am trying to filter out invalid url from valid ones using .NET. I
I'm trying to filter out some garbage text from a string with regex but
I am trying to filter out all characters before the first / sign. I
I'm trying to filter some XML in JavaScript using E4X and have some specific
I am trying to filter out the noise from the orientation/compass sensor in my
I am trying to filter out the duplicates of a subset of columns from
Magento 1.3 I'm trying to filter out of stock items from the productCollection. Using:

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.