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 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 build c++ boost to work with qt creator but
I have been trying to build an online java compiler. But running the clients
I have been trying to get this to work for about three solid days
I have been trying for months to get numpy installed for Python 3 but
I have been trying to get my head around to make things work with
I have been trying for days to get my gitolite work with jenkins so
I'm trying to build a regular expression where I been asked to filter string
I have been trying to get the pygame module to work with python3 in
I have been trying to build SVM classifier but having trouble with predict .
I have been trying to learn how to build jQuery plugins, so I'm still

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.