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

  • Home
  • SEARCH
  • 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 6664263
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:35:28+00:00 2026-05-26T02:35:28+00:00

In VB.net I’ve got the following line that removes all non-alphanumeric chars from a

  • 0

In VB.net I’ve got the following line that removes all non-alphanumeric chars from a string:

return Regex.Replace(build, "[\W]", "")

I now need to extend this to remove non-alphanumeric chars that aren’t [] or _.

I’ve changed the line to:

return Regex.Replace(build, "[\W\[\]_]", "")

However I’m pretty sure that this says

replace non-word or [ or ] or _

how do I negate the tests for the [] and _ chars so that it says

replace non-word and not [ and not ] and not _

Some examples:

"[Foo Bar_123456]" => "[FooBar_123456]"
"[Foo Bar_123-456*]" => "[FooBar_123456]"

(More can be supplied if necessary)

  • 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-26T02:35:29+00:00Added an answer on May 26, 2026 at 2:35 am

    You can use character set subtraction:

    [\W-[_\[\]]]
    

    Ie. \W with _, [ and ] removed (latter two needing an escape because they are meta-characters in a character set). A verbatim string @"..." avoids needing to escape each backslash from C#:

    var re = new Regex(@"[\W-[_\[\]]]");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

.NET balanced group regexes make my head explode. I've got this string i'm trying
.NET newbie here... I'd like to make a button in a Windows form that
.Net framework contains a great class named Convert that allows conversion between simple types,
net ajax app. I have one modelpopup that shows a IFrame and inside Iframe
.NET 3.5 was different and co-existed along with .NET 2.0. Is that still the
.NET Programming guidelines state that we should not catch general exceptions. I assume the
.NET 4.0 don't use medium trust it got a different kind of security, does
Net application and from one page i have to redirect to silverlight page, i
net CF I need to use substring to capture the mid of a string.
net project then it runs in mozilla. I want to change that setting &

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.