You should use the string replace function, with a single regex. Assuming by special characters, you mean anything that's not letter, here is a solution:

const str = "abc's test#s";
console.log(str.replace(/[^a-zA-Z ]/g, ""));
Run code snippetEdit code snippet Hide Results Copy to answer Expand

Answer from Petar Ivanov on Stack Overflow
🌐
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.
Discussions

Remove specific characters from a string in Javascript - Stack Overflow
I am creating a form to lookup the details of a support request in our call logging system. Call references are assigned a number like F0123456 which is what the user would enter, but the record in... More on stackoverflow.com
🌐 stackoverflow.com
Removing special characters from a string
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"; ... More on forum.freecodecamp.org
🌐 forum.freecodecamp.org
13
0
July 30, 2017
regex - How to remove special characters from a string using Javascript - Stack Overflow
Could someone please help me to remove special characters from a string using javascript or Jquery. Note: I would like to remove only a specific set of special characters but not replacing it wit... More on stackoverflow.com
🌐 stackoverflow.com
javascript - Remove all special characters with RegExp - Stack Overflow
I would like a RegExp that will remove all special characters from a string. I am trying something like this but it doesn’t work in IE7, though it works in Firefox. var specialChars = "!@#$^&%... More on stackoverflow.com
🌐 stackoverflow.com
🌐
Coding Beauty
codingbeautydev.com › home › posts › how to remove special characters from a string in javascript
How to Remove Special Characters From a String in JavaScript
October 13, 2022 - To remove all special characters from a string, call the replace() method on the string, passing a whitelisting regex and an empty string as arguments, i.e., str.replace(/^a-zA-Z0-9 ]/g, '').
🌐
Delft Stack
delftstack.com › home › howto › javascript › javascript remove special characters
How to Remove Special Characters in JavaScript | Delft Stack
February 2, 2024 - <!DOCTYPE html> <html> <head> <title> Remove Special Characters</title> </head> <body> <h2>The Original String</h2> <p id="stringValue">Do [a search-for special characters] in string &:search and, "remove"#@ them:</p> <h2>String After Replacement</h2> <p id="demo"></p> </body> </html> ... var specialChars = '!@#$^&%*()+=-[]\/{}|:<>?",.'; var stringValue = $('#stringValue').text(); for (var i = 0; i < specialChars.length; i++) { stringValue = stringValue.replace(new RegExp('\\' + specialChars[i], 'g'), ''); } $('#demo').text( stringValue) // text() returns the text content of the selected element.
🌐
RSWP Themes
rswpthemes.com › home › javascript tutorial › how to remove spaces and special characters from a string in javascript
How to Remove Spaces and Special Characters from a String in JavaScript
June 3, 2025 - The regex method str.replace(/[^a-zA-Z0-9]/g, '') is the most flexible and efficient for removing special characters while keeping alphanumeric ones. Regex is often the fastest for complex patterns. For simple tasks like removing spaces, string methods like trim() or split()/join() can be sufficient and more readable. Cleaning strings in JavaScript is straightforward with regex or string methods.
Find elsewhere
🌐
Code Beautify
codebeautify.org › blog › remove-special-sharacters-from-string-javascript
Remove Special Characters From String Javascript
February 22, 2024 - Approach 1 : 1 2 3 4 5 6 7 8 9 10 11 function removeSpecialCharacters(inputString) { // Use a regular expression to match and replace special characters return inputString.replace(/[^\w\s]/gi, ''); } // Example usage: const originalString = "Hello!
🌐
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);
🌐
TutorialsPoint
tutorialspoint.com › article › javascript-regex-how-to-replace-special-characters
JavaScript regex - How to replace special characters?
The replace() method with regex patterns provides a powerful way to remove or replace special characters in JavaScript strings.
🌐
sebhastian
sebhastian.com › javascript-remove-special-characters-from-string
JavaScript Remove Special Characters From a String | sebhastian
October 25, 2023 - To remove special characters from a JavaScript string, you need to use the replace() method and define a regular expression to search for the special characters that need to be removed.
🌐
YouTube
youtube.com › watch
Remove special Characters from a String in JavaScript (Article Demo #13) | Online Web Tutor - YouTube
In this video we'll see:Remove special Characters from a String in JavaScript (Article Demo #13) | Online Web TutorArticle URLhttps://onlinewebtutorblog.com/...
Published   August 20, 2022
🌐
Medium
medium.com › coding-beauty › javascript-remove-special-characters-from-string-74e4db3b3bb0
How to Remove Special Characters From a String in JavaScript - Coding Beauty | Coding Beauty
October 18, 2022 - So the regex matches any character is not a lowercase or uppercase letter, digit or space, and the replace() method returns a new string with all of these characters removed from the original string. The g (global) flag specifies that every occurrence of the pattern should be matched. If we don’t pass a global flag, only the first special character in the string will be matched and removed.
🌐
YouTube
youtube.com › watch
How do I remove special characters in a string in JavaScript? - YouTube
Please do like share and comment if you like the video please do hit like and if you have any query please write it comment box How do I remove special chara...
Published   March 15, 2023
🌐
SmartWiki
wiki.smartsimple.com › wiki › Removing_Special_Characters
Removing Special Characters - SmartWiki
onkeyup=javascript:this.value=this.value.replace(/["]/g,'\''); 3. To restrict user to only enter Integers write this code in the HTML tag box: onkeyup="this.value=this.value.replace(/[\D]/g,'');" ... Retrieved from ‘https://wiki.smartsimple.com/index.php?title=Removing_Special_Characters...
🌐
Metring
ricardometring.com › javascript-replace-special-characters
JavaScript: Replacing Special Characters - The Clean Way
Removing punctuation in JavaScript is a relatively easy task, but removing accents, leaving only the letters is a bit more challenging. Regardless of the situation, I have below some minimalist functions that can be used for both cases. To simply remove accents and cedilla from a string and return the same string without the accents, we can use ES6's String.prototype.normalize method, followed by a String.prototype.replace:
🌐
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...
🌐
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 - To remove special characters from a String in JavaScript, we have to use regular expressions with the String.prototype.replace() method.