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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:07:34+00:00 2026-05-31T13:07:34+00:00

I need a function to remove all characters except numbers + characters: ‘$’, ‘.’

  • 0

I need a function to remove all characters except numbers + characters: ‘$’, ‘.’ and ‘,’.

How can I do this?

  • 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-31T13:07:35+00:00Added an answer on May 31, 2026 at 1:07 pm
    > 'worth $12,345.00 dollars'.replace(/[^0-9$.,]/g, '')
    "$12,345.00"
    

    This is the answer you asked for. I would not recommend it for extracting currencies, since it can suffer from problems like this:

    > 'A set of 12 worth between $123 and $456. A good buy.'.replace(/[^0-9$.,]/g, '')
    "12$123$456.."
    

    If you want to just extract expressions of a currency-like form, you could do:

    > 'set of 12 worth between $123.00 and $45,678'.match(/\$[0-9,]+(?:\.\d\d)?/g)
    ["$123.00", "$45,678"]
    

    If you need more complicated matching (e.g. you’d just like to extract the dollar value and ignore the cent value) you could do something like How do you access the matched groups in a JavaScript regular expression? for example:

    > var regex = /\$([0-9,]+)(?:\.(\d\d))?/g;
    > while (true) {
    >     var match = regex.exec('set of 12 worth between $123.00 and $45,678');
    >     if (match === null)
    >         break;
    >     console.log(match);
    > }
    ["$123.00", "123", "00"]
    ["$45,678", "45,678", undefined]
    

    (Thus be careful, javascript regexp objects are not immutable/final objects, but have state and can be used for iteration as demonstrated above. You thus cannot “reuse” a regexp object. Even passing myRegex2 = RegExp(myRegex) will mix state; a very poor language decision for the constructor. See the addendum on how to properly clone regexes in javascript.) You can rewrite the above as a very exotic for-loop if you’d like:

    var myString = 'set of 12 worth between $123.00 and $45,678';
    var regex = '\$([0-9,]+)(?:\.(\d\d))?';
    
    for(var match, r=RegExp(regex,'g'); match=regex.exec(myString) && match!==null; )
        console.log(match);
    

    addendum – Why you can’t reuse javascript RegExp objects

    Bad language design, demonstrating how state is reused:

    var r=/(x.)/g
    var r2 = RegExp(r)
    
    r.exec('xa xb xc')
    ["xa", "xa"]
    r2.exec('x1 x2 x3')
    ["x2", "x2"]
    

    How to properly clone a regex in javascript (you have to define it with a string):

    var regexTemplate = '(x.)'
    
    var r = RegExp(regexTemplate, 'g')
    var r2 = RegExp(regexTemplate, 'g')
    
    r.exec('xa xb xc')
    ["xa", "xa"]
    r2.exec('x1 x2 x3')
    ["x1", "x1"]
    

    If you wish to programmatically preserve flags such as 'g', you can probably use regexTemplate = ['(x.)', 'g']; RegExp.apply(this, regexTemplate).

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

Sidebar

Related Questions

We need a C# function which will remove all special characters from a string.
how can i to remove all characters non-language ? i want to remove characters
I need a php function to remove all the whitespaces in a string. I
I need to remove all characters from a string which aren't in a-z A-Z
I need a function in sql server to build all of changed word in
I need a function that I can call when somthing is done, for example
I need a function that can return the difference between the below two dates
I need to remove some html markup that occurs inside an img tag. This
Hello I have this function that will delete all the empty fields in the
Is there an easy way to remove all non alphanumeric characters from a string

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.