This will match everything that is not numeric or not a comma or period (decimal point)

var result = str.replace(/[^0-9\.,]/g, "");
Answer from Ding on Stack Overflow
🌐
TutorialsPoint
tutorialspoint.com β€Ί article β€Ί javascript-regex-how-to-replace-special-characters
JavaScript regex - How to replace special characters?
For this we use replace() method. The JavaScript built-in method string.replace() can be used to replace a portion of a supplied string with another string or a regular expression.
Discussions

How to Remove Special Characters in this Javascript Code - Stack Overflow
How do I remove special characters in the specific code below? I've been trying to use replace with var = t, but it has not worked properly. When a person enters a comma in the number they want More on stackoverflow.com
🌐 stackoverflow.com
Remove all special characters except space from a string using JavaScript - Stack Overflow
I want to remove all special characters except space from a string using JavaScript. For example, abc's test#s should output as abcs tests. More on stackoverflow.com
🌐 stackoverflow.com
Replacing space and comma from a string using regex
I may get a string like this: 23,45,567 23,45 56 7 I want it to free of all the commas and spaces. So, I tried to use the following codes: β€œ23,45,567”.replace(β€˜/[1]$/g’, β€˜β€™) β€œ23,45,567”.replace(β€˜/[2]+$/g’, β€˜β€™) β€œ23,45,567”.replace(β€˜/^\s,$/g’, β€˜β€™) And many ... More on forum.freecodecamp.org
🌐 forum.freecodecamp.org
3
0
October 26, 2020
Javascript replace special characters - Stack Overflow
Let's say I want to replace this: Test Test into this: Test\X20\Test I know this sounds weird but I need for the string to look like that. And I can't get my head around this because of the l... More on stackoverflow.com
🌐 stackoverflow.com
🌐
CoreUI
coreui.io β€Ί answers β€Ί how-to-remove-special-characters-from-a-string-in-javascript
How to remove special characters from a string in JavaScript Β· CoreUI
May 20, 2026 - Use replace() with regular expressions to efficiently remove special characters from strings in JavaScript.
🌐
Stack Overflow
stackoverflow.com β€Ί questions β€Ί 33236868 β€Ί how-to-remove-special-characters-in-this-javascript-code
How to Remove Special Characters in this Javascript Code - Stack Overflow
Removing the comma won't be an issue in the BIRT report that I'm using 2015-10-20T13:45:29.553Z+00:00 ... Well glad to hear that, yeah @Paul-Jan you are right. 2015-10-20T14:02:01.333Z+00:00 ... ParseFloat doesn't support thousand separators. If you want to support user input containing such separators, you'll have to manually strip them off. function toWords(n) { var n=parseFloat(n.replace(',','')).toFixed(2); ...
🌐
MDN Web Docs
developer.mozilla.org β€Ί en-US β€Ί docs β€Ί Web β€Ί JavaScript β€Ί Reference β€Ί Global_Objects β€Ί String β€Ί replace
String.prototype.replace() - JavaScript - MDN Web Docs
The replace() method of String values returns a new string with one, some, or all matches of a pattern replaced by a replacement. The pattern can be a string or a RegExp, and the replacement can be a string or a function called for each match. If pattern is a string, only the first occurrence ...
🌐
EyeHunts
tutorial.eyehunts.com β€Ί home β€Ί javascript replace all word | space, comma | special characters
How to JavaScript replace all Word | Space, Comma | Special Character
May 15, 2021 - <!DOCTYPE html> <html> <script> var string = 'EyeHunts Tutorial JS'; var newstring = string.replace(/JS/, 'Javascript'); document.write(newstring); </script> <body> </body> </html> ... The best way is to use regular expression with g (global) flag. ...
Find elsewhere
🌐
Metring
ricardometring.com β€Ί javascript-replace-special-characters
JavaScript: Replacing Special Characters - The Clean Way
Then the method replaces all occurrences of diacritical characters, combining them in the Unicode sequence \u0300 - \u036F, another advantage of ES6 that was added to allow Unicode ranges in RegEx. To remove the accents and other special characters like /?!(), just use the same formula above, only replace everything but letters and numbers.
🌐
freeCodeCamp
forum.freecodecamp.org β€Ί programming β€Ί javascript
Replacing space and comma from a string using regex - JavaScript - The freeCodeCamp Forum
October 26, 2020 - I may get a string like this: 23,45,567 23,45 56 7 I want it to free of all the commas and spaces. So, I tried to use the following codes: β€œ23,45,567”.replace(β€˜/[1]$/g’, β€˜β€™) β€œ23,45,567”.replace(β€˜/[2]+$/g’, β€˜β€™) β€œ23,45,567”.replace(β€˜/^\s,$/g’, β€˜β€™) And many more like this.
🌐
Bobby Hadz
bobbyhadz.com β€Ί blog β€Ί javascript-remove-special-characters-from-string
Remove special Characters from a String in JavaScript | bobbyhadz
Use the `replace()` method to remove all special characters from a string, e.g. `str.replace(/[^a-zA-Z0-9 ]/g, '');`.
🌐
SitePoint
sitepoint.com β€Ί javascript
Efficient way of replacing special characters - JavaScript - SitePoint Forums | Web Development & Design Community
April 9, 2024 - Suppose I have a string like this: This is a fridge with 10 chocolates and ~5 icecream samples description to check if backward slash \ breaks anything and checking caret ^ symbol as well I want to replace those special characters with the following: \ to \1F ~ to \7E ^ to \5E I may find more to replace in future but at this point I just want to handle above such that after replacing it, the string looks like the following: This is a fridge with 10 horse and \7E5 goat samples descriptio...
🌐
DEV Community
dev.to β€Ί maafaishal β€Ί javascript-stringreplace-useful-cases-3963
JavaScript `string.replace()` useful cases - DEV Community
September 24, 2024 - To replace characters that aren't in the ASCII range, you can use Unicode properties. let str = "HΓ©llo WΓΆrld"; let result = str.replace(/[^\x00-\x7F]/g, ""); // Output: "Hllo Wrld" You can replace digits (or groups of digits) using regular ...
🌐
freeCodeCamp
forum.freecodecamp.org β€Ί programming
Removing special characters from a string - Programming - The freeCodeCamp Forum
July 30, 2017 - Currently working on making a palindrome function. I have the gist of it. Just can’t get this last part. I’ve tried so many examples from so many stockoverflow posts and this still doesn’t work for me. Can someone help me figure out what’s wrong? var str = "abc's test#s"; str.replace(/[&\/\\#,+()$~%.'":*? {}]/g,'_'); console.log(str);
🌐
Stack Overflow
stackoverflow.com β€Ί questions β€Ί 67499160 β€Ί replace-comma-with-special-characters-in-javascript
node.js - Replace comma with special characters in Javascript - Stack Overflow
I don't know your use case, but "\" isn't a valid URL character unless it's properly encoded. See this post. ... @DrewReese Yeah.. I know adding "\" will make it invalid URL, but I want to consider it as string. Actually my intention here is to escape comma, so to do that I wanted to add '\' before comma.
🌐
TutorialsPoint
tutorialspoint.com β€Ί article β€Ί replace-commas-with-javascript-regex
Replace commas with JavaScript Regex?
We want to replace the last comma in each string with " JavaScript". The regular expression /,(?=[^,]*$)/ matches a comma that is followed by any characters except commas until the end of the string, effectively targeting the last comma.
🌐
Intellipaat
intellipaat.com β€Ί home β€Ί blog β€Ί remove all special characters except space from a string using javascript
Remove all special characters except space from a string using JavaScript - Intellipaat
February 3, 2026 - So far in this article, we have learned how we can remove all special characters except space from a string using regular expressions in JavaScript. We have to use replace() function and match() to do this task.