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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:54:44+00:00 2026-06-15T10:54:44+00:00

I am trying to do a basic string replace using a regex expression, but

  • 0

I am trying to do a basic string replace using a regex expression, but the answers I have found do not seem to help – they are directly answering each persons unique requirement with little or no explanation.

I am using str = str.replace(/[^a-z0-9+]/g, ''); at the moment. But what I would like to do is allow all alphanumeric characters (a-z and 0-9) and also the ‘-‘ character.

Could you please answer this and explain how you concatenate expressions.

  • 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-06-15T10:54:45+00:00Added an answer on June 15, 2026 at 10:54 am

    This should work :

    str = str.replace(/[^a-z0-9-]/g, '');
    

    Everything between the indicates what your are looking for

    1. / is here to delimit your pattern so you have one to start and one to end
    2. [] indicates the pattern your are looking for on one specific character
    3. ^ indicates that you want every character NOT corresponding to what follows
    4. a-z matches any character between ‘a’ and ‘z’ included
    5. 0-9 matches any digit between ‘0’ and ‘9’ included (meaning any digit)
    6. - the ‘-‘ character
    7. g at the end is a special parameter saying that you do not want you regex to stop on the first character matching your pattern but to continue on the whole string

    Then your expression is delimited by / before and after.
    So here you say “every character not being a letter, a digit or a ‘-‘ will be removed from the string”.

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

Sidebar

Related Questions

I'm trying to split a string using the method found in this thread ,
I'm not really that good with regex, but I understand the basics. I'm trying
Pretty basic stuff here, trying to pull the number 14.5 out of this string
I'm trying the basic jMonkey but I get this exception jun 27, 2012 9:25:08
I have a very basic understanding of shell scripting, but what I need to
I trying to do some very basic string processing in C (e.g. given a
I've recently been trying to teach myself Perl and have been doing some basic
I have a problem trying to understand the code of a basic nodelist. The
I am trying to come up with a case insensitive string, and I found
Just a simple question, Im trying to replace class with var, but obviously 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.