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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T19:33:15+00:00 2026-05-21T19:33:15+00:00

i am using the following regex [^a-zA-Z\d!-] pattern in c# to clean special characters

  • 0

i am using the following regex [^a-zA-Z\d!-] pattern in c# to clean special characters from filename so i can pull basic information from it and build initial class property values from it

how ever no matter what i seem to do it wont clean the square brackets from the string according to regex builder it should be matching the square brackets but is not removing them when i run the replace operation

any help as to why would be greatly appreciated and a fix would be nice too =)

the code im using in c# is as follows:

var removeSpecChar = new Regex(@"[^a-zA-Z\d!-]");               

msa = msa.Substring(0, msa.Length - 4);
removeSpecChar.Replace(msa, " ").Trim();
  • 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-21T19:33:16+00:00Added an answer on May 21, 2026 at 7:33 pm

    Didn’t try, but you really should escape the - in characher sets:

    var removeSpecChar = new Regex(@"[^a-zA-Z\d!\-]"); 
    

    Also note that \d is not equivalent to 0-9, it matches any unicode digit (including arabic digits etc.). So you may want to change that if this isn’t your intention.

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

Sidebar

Related Questions

Can someone help me to validate the following rules using a RegEx pattern Max
I'm using java.util.regex.Pattern to match passwords that meet the following criteria: At least 7
I am using RegexKitLite and I'm trying to match a pattern. The following regex
I'm using the following javascript regex: var pattern = new RegExp(^ + term +
I am using the following regex to get the src value of the first
I'm using the following regex to validate password complexity: /^.*(?=.{6,12})(?=.*[0-9]{2})(?=.*[A-Z]{2})(?=.*[a-z]{2}).*$/ In a nutshell: 2
I'm matching the following strings: watermark=testing watermark=text-testing|position-24-50 watermark=text-testing|position-24-50|color-6aa6cc watermark=text-testing|position-24-50|color-6aa6cc|size-48 using the following regex: watermark=(text-\w+\|position-\d+-\d+\|color-([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})\|size-\d+|text-\w+\|position-\d+-\d+\|color-([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})|text-\w+\|position-\d+-\d+|\w+)
Consider following string Some string with quotes and \pre-slashed\ quotes Using regex, I want
I have to validate using regex decimal number between 00.00 to 35.35 with following
Ok, this is really really weird. I have the following simple regex search pattern

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.