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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T08:48:36+00:00 2026-05-18T08:48:36+00:00

I have been trying to build a regular expression but haven’t been able to

  • 0

I have been trying to build a regular expression but haven’t been able to get one specific condition to work.

I want a regex to remove all non alpha characters with the exception of dash (-). Dashes should only be replaced if they are prefixed by a space.

I.e.

TEST-TEST -TEST#TEST.TEST

should be changed to

TEST-TEST TEST TEST TEST

I had been using [^a-zA-Z0-9] but haven’t been able to include one OR condition init.

  • 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-18T08:48:37+00:00Added an answer on May 18, 2026 at 8:48 am

    Here is what I came up with (\s-|[^A-Za-z0-9-])… It will remove all non alphanumerics but keep the “-” except if there is a space before it ” -“

    Test using sed in Linux, at the moment I don’t have access to VS or Mono to test in C#

    echo "TEST-TEST -TEST#TEST.TEST -1234" | sed 's/\(\s-\|[^A-Za-z0-9-]\)/ /g'
    

    Output

    TEST-TEST TEST TEST TEST 1234
    
    • () and | are used for the OR condition
    • We first remove all ” -” using \s-
    • next we keep all alphanumerics and “-” with [^A-Za-z0-9-]
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been trying to get culture specific resources to work on an asp.net
I have been trying to work my way through Project Euler, and have noticed
I have been trying to get around this error for a day now and
I have been trying to make a case for using Python at my work.
I'm trying to build a regular expression that will detect any character that Windows
I have been trying to build a user control with some custom properties set
I have been trying to build only the /libcore directory of the Android platform.
I have been trying to use the gem 'character-encodings' which doesn't build in 1.9.2
I have been trying to use reflection for a specifiec Field in the android.os.build
I am new to Mozilla extensions and i have been trying to build the

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.