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 Top answer 1 of 13
570
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
2 of 13
211
You can do it specifying the characters you want to remove:
string = string.replace(/[&\/\\#,+()$~%.'":*?<>{}]/g, '');
Alternatively, to change all characters except numbers and letters, try:
string = string.replace(/[^a-zA-Z0-9]/g, '');
freeCodeCamp
forum.freecodecamp.org › curriculum help
Removing special characters from a string - Curriculum Help - 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);
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
Removing Special Characters Using an Built In Function | OutSystems
Removing Special Characters Using an Built In Function More on outsystems.com
Efficient way of replacing special characters - JavaScript - SitePoint Forums | Web Development & Design Community
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 ... More on sitepoint.com
How can i remove special characters and spaces from a string
How can i remove all special characters and spaces from a string. So that are only letters in the string. Many thanks! More on community.tadabase.io
04:48
Remove All Special Characters from String — JavaScript Regex ...
04:05
How to remove special characters from a given string using JavaScript.
01:45
How do I remove special characters in a string in JavaScript? - ...
03:00
How can I remove a specific character from a string in JavaScript?
05:48
Frequently Asked Java Program 24: How To Remove Junk or ...
06:07
How to Remove all special characters with RegExp in JS - YouTube
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...
OutSystems
outsystems.com › forums › discussion › 76022 › removing-special-characters-using-an-built-in-function
Removing Special Characters Using an Built In Function | OutSystems
January 27, 2022 - Removing Special Characters Using an Built In Function
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.
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...
Top answer 1 of 6
91
Simply replace it with nothing:
var string = 'F0123456'; // just an example
string.replace(/^F0+/i, ''); '123456'
2 of 6
32
Honestly I think this probably the most concise and least confusing, but maybe that is just me:
str = "F0123456";
str.replace("f0", "");
Dont even go the regular expression route and simply do a straight replace.
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).
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.
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 · Discuss anything relevant to the GameMaker ...