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

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
Get rid of special characters in string
Not a bubble question - a javastring question. Have some problems getting .replace to work when removing special characters from a string of special characters. For most special characters, just using the special character works. For others like $ or ^, using the special character doesn’t work. More on forum.bubble.io
🌐 forum.bubble.io
13
0
July 1, 2023
How do i remove special characters from a string?
hi all, i have seen it been done using REGEX but i would like to know how to do it without as mine doesn’t appear to be working Thank you More on forum.uipath.com
🌐 forum.uipath.com
11
8
January 27, 2020
Removing Special Characters Using an Built In Function | OutSystems
Removing Special Characters Using an Built In Function More on outsystems.com
🌐 outsystems.com
January 27, 2022
🌐
freeCodeCamp
forum.freecodecamp.org › programming
Removing special characters from a string - JavaScript
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);
🌐
Bubble
forum.bubble.io › need help
Get rid of special characters in string - Need help - Bubble Forum
July 1, 2023 - Not a bubble question - a javastring question. Have some problems getting .replace to work when removing special characters from a string of special characters. For most special characters, just using the special chara…
🌐
UiPath Community
forum.uipath.com › help
How do i remove special characters from a string? - Help - UiPath Community Forum
January 27, 2020 - hi all, i have seen it been done using REGEX but i would like to know how to do it without as mine doesn’t appear to be working Thank you
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › replace-special-characters-in-a-string-with-underscore-_-in-javascript
Replace special characters in a string with underscore (_) in JavaScript - GeeksforGeeks
July 11, 2025 - In this example, we replace a unique special character with _ (underscore). This example spread function is used to form an array from a string and form a string with the help of reduce which excludes all special character and add underscore in their places.
🌐
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...
🌐
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...
🌐
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!
🌐
TutorialsPoint
tutorialspoint.com › how-to-replace-all-the-special-characters-following-another-character-ndash-javascript
JavaScript regex - How to replace special characters?
April 21, 2023 - The replace() method with regex patterns provides a powerful way to remove or replace special characters in JavaScript strings.
🌐
Unreal Engine
forums.unrealengine.com › development › programming & scripting
What's the best way to remove letters and special characters from a string? - Programming & Scripting - Epic Developer Community Forums
February 6, 2023 - Hi, I’m trying to remove letters and other special characters from a string but I’m not finding the best way to do it. I’ve tried the Replace function but it only works with a single character at a time or a complete string. What I’m trying to accomplish is to only keep the digits on ...
🌐
Mozilla
developer.mozilla.org › en-US › docs › Web › JavaScript › Guide › Regular_expressions
Regular expressions - JavaScript | MDN
A regular expression pattern is composed of simple characters, such as /abc/, or a combination of simple and special characters, such as /ab*c/ or /Chapter (\d+)\.\d*/. The last example includes parentheses, which are used as a memory device. The match made with this part of the pattern is remembered for later use, as described in Using groups. Simple patterns are constructed of characters for which you want to find a direct match. For example, the pattern /abc/ matches character combinations in strings only when the exact sequence "abc" occurs (all characters together and in that order).
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › how-to-remove-a-character-from-string-in-javascript
Remove a Character From String in JavaScript - GeeksforGeeks
February 25, 2026 - One of the most common methods to remove a character from a string is by using the replace() method. This method searches for a specified character or pattern in a string and replaces it with something else, which can be an empty string ("") ...
🌐
SmartBear
support.smartbear.com › testcomplete › docs › scripting › working-with › strings › javascript.html
JavaScript - Working With Strings | TestComplete Documentation
Some scripting objects, generally, controls like ListBoxes, ComboBoxes, Memos, return data about their state or contents as string lists. The individual data elements (or items) in this list are separated by commas, line breaks, carriage returns or some other delimiter characters. The aqString object has a number of specific methods (AddListItem, ChangeListItem, DeleteListItem, GetListItem and GetListLength) that are intended to deal with such lists of textual data. The AddListItem and DeleteListItem append the item to the list and remove the item from the list.
🌐
W3Schools
w3schools.com › js › js_strings.asp
JavaScript Strings
Templates are strings enclosed ... will be chopped to "We are the so-called ". To solve this problem, you can use an backslash escape character....
🌐
GameMaker Community
forum.gamemaker.io › forum home
Remove all special chars from string except "_"
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding · You are using an out of date browser. It may not display this or other websites correctly. You should upgrade or use an alternative browser · Should I implement file encryption in ...
🌐
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.