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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:38:24+00:00 2026-05-23T13:38:24+00:00

I want to filter out special characters in C#. Basically i want to allow

  • 0

I want to filter out special characters in C#.
Basically i want to allow A-Z, a-z, 0-9, hyphen, underscore, (, ), commas, spaces, \, /, spaces.
Everything else is not allowed.

I have come up with the following regex ->

[a-zA-Z0-9-\b/(),_\s]*

but this doesn’t seem to work fine.

Am I missing something?

  • 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-23T13:38:24+00:00Added an answer on May 23, 2026 at 1:38 pm

    If you want to filter out characters that don’t match those, use a ^ at the beginning of the character class:

    [^a-zA-Z0-9\-\\/(),_\s]+
    

    The + quantifier will match any chars not in the character class at least once. Also, hyphens are meta characters inside character classes, so you should escape the dangling one you have, as I have done in my example. Also, if you want to include \ as an allowed character, you also need to escape it inside a character class, like [\\].

    Also, inside a character class (also known as a character set defined by [ ]), \b is a backspace character, not a word boundary.

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

Sidebar

Related Questions

I want to filter out those with field not like '%_[0-9]+' , but it
Let's say I have this string(huge), and I want to filter out everything but
I want to filter out duplicate customer names from a database. A single customer
I want to filter out several key phrases out of a dataset. Unfortunately, the
I want to filter out the output without rows containing null values or blank
I have List List courseTakenList.i want to filter out the Status which are in
When I retrieve Document from MongoDB, I want to filter out the id field
Say I have a list of strings, and I want to filter out all
I want to filter out certain lines from stack traces using log4j (like net.sf.cglib.*
I want to filter out all values of var3 < 5 while keeping at

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.