Use the global flag:

var name = name.replace(/[^a-zA-Z ]/g, "");
                                    ^

If you don't want to remove numbers, add it to the class:

var name = name.replace(/[^a-zA-Z0-9 ]/g, "");
Answer from Jerry on Stack Overflow
🌐
Reddit
reddit.com › r/learnprogramming › using regex to remove non-alphabetical characters in a string.
r/learnprogramming on Reddit: Using regex to remove non-alphabetical characters in a string.
July 24, 2021 -

Hi, I am trying to remove non-alphabetical characters from the following string.

let string = "Anne, I vote more cars race Rome-to-Vienna"

I can get the result I am looking for with the following...

let newString = string.toLowerCase().split('').filter(el => el !== ' ' && el !== '-' && el !== ',').join('')

However I would prefer to use a much shorter piece of code using regex. I have gone over a few regex examples and tutorials but it still kind of confused me. Does anybody know the simplest way to remove the unwanted characters from the above string?

Thanks!!!

Discussions

Regex to remove special characters
Hi community Happy new year, I'm not to good with RegEx but I know it is needed in my use case. I have these company names but they contain special characters and i'm not sure how to remove them. I've attached a mini dummy sample of the data below. Any assistance with this would be majorly ... More on community.alteryx.com
🌐 community.alteryx.com
January 5, 2023
RegexReplace for Special Character
Hi, I would like to replace any character with blank . Only valid characters are A-Za-z0-9Space. Anything other than this should be replaced with blank. Thanks More on forum.knime.com
🌐 forum.knime.com
0
0
October 10, 2023
How to remove a special characters in a given string by regex
how to remove a special characters in a given string by regex? “philippines nt., (Roosevelt Ave 3), St@a. philippines City, @U/SA” More on forum.uipath.com
🌐 forum.uipath.com
8
0
September 27, 2023
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
🌐
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
🌐
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 - The transliteration map converts accented characters to their ASCII equivalents before the regex strips anything remaining. For more on string replacement, see how to replace all occurrences of a string in JavaScript. File systems have strict rules about allowed characters. Sanitizing filenames prevents errors and security issues when saving user-provided names. // Remove characters not allowed in most file systems const sanitizeFilename = (filename) => { return filename .replace(/[<>:"/\\|?*\x00-\x1F]/g, '') // forbidden chars .replace(/\s+/g, '_') // spaces to underscores .replace(/^\.+/, ''
🌐
TutorialsPoint
tutorialspoint.com › article › javascript-regex-how-to-replace-special-characters
JavaScript regex - How to replace special characters?
Use /[^a-zA-Z0-9]/g to remove all special characters or create custom patterns for specific requirements.
Find elsewhere
🌐
iAm_ManCat Blog
iammancat.dev › home › remove characters from strings using regex in power apps
Remove characters from strings using Regex in Power Apps - iAm_ManCat Blog
March 17, 2023 - Normally we’d be using that kind of formula to ensure there are no special characters like hyphens or apostrophes so that when we have to pass that data to something that needs to create folders for example, then it will not fail due to the presence of special characters. If you want to validate characters for names and include the hyphen and apostrophe characters you can simply add them to the regex string array (you can use the following Regex string in place of the one listed): “[A-Za-z0-9 ‘-]”
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-removing-unwanted-characters-from-string
Remove Special Characters from String in Python - GeeksforGeeks
July 11, 2025 - Let's explore different methods to achieve this. re.sub() function from re module allows you to substitute parts of a string based on a regex pattern. By using a pattern like [^a-zA-Z0-9], we can match and remove all non-alphanumeric characters.
🌐
Text-Utils
text-utils.com › remove special characters
Remove Special Characters - Online Regex Tools | Text-Utils.com
September 6, 2025 - Keep ASCII only: Remove all non-ASCII characters from the text. See the examples of usage below. ... Follow these steps to quickly delete unwanted symbols from the input.
🌐
ServiceNow Community
servicenow.com › community › developer-forum › using-regex-to-make-special-characters-disappear-except-when-it › m-p › 2574305
Using regex to make special characters disappear except when it is a dash. How do you do that?
May 31, 2023 - Correct. All the '-' signs are removed earlier within your step 1, since these are considered to be special characters. You can modify your step 1 and include '-' in your existing regex.
🌐
Quora
quora.com › Can-special-characters-be-removed-from-a-string-using-regex
Can special characters be removed from a string using regex? - Quora
Answer: There are already direct answers and yes of course Nginx can do this. However, one should note something highly special about Nginx configs and Runtime… If you are familiar with the concept “ABC is a first-class citizen in XYZ” many people are not aware that values are first-class ...
🌐
C# Corner
c-sharpcorner.com › blogs › replace-special-characters-from-string-using-regex1
Replace Special Characters from string using Regex
February 18, 2015 - Regex.Replace(your String, @"[^0-9a-zA-Z]+", "") This code will remove all of the special characters but if you doesn't want to remove some of the special character for e.g.
🌐
Medium
medium.com › @vidvatek › how-to-remove-special-characters-from-string-in-python-13b04516421a
How to Remove Special Characters from String in Python | Medium
December 15, 2023 - The regular expression [^\w\s] ... ... This code demonstrates how to remove special characters from a string using the re.sub() function and regular expressions in Python....
🌐
Python documentation
docs.python.org › 3 › library › re.html
re — Regular expression operations
May 25, 2026 - Source code: Lib/re/ This module provides regular expression matching operations similar to those found in Perl. Both patterns and strings to be searched can be Unicode strings ( str) as well as 8-...
🌐
KNIME Community
forum.knime.com › knime analytics platform
RegexReplace for Special Character - KNIME Analytics Platform - KNIME Forum Archive
October 10, 2023 - Hi, I would like to replace any character with blank . Only valid characters are A-Za-z0-9Space. Anything other than this should be replaced with blank. Thanks
🌐
UiPath Community
forum.uipath.com › help › studio
How to remove a special characters in a given string by regex - Studio - UiPath Community Forum
September 27, 2023 - how to remove a special characters in a given string by regex? “philippines nt., (Roosevelt Ave 3), St@a. philippines City, @U/SA”
🌐
LazyWinAdmin
lazywinadmin.com › 2015 › 08 › powershell-remove-special-characters.html
PowerShell - Remove special characters from a string using Regular Expression (Regex) - LazyWinAdmin
August 30, 2015 - # Regular Expression - Unicode - Unicode Categories # Exceptions: We want to keep the following characters: ( } _ $String -replace '[^\p{L}\p{Nd}/(/}/_]', '' ... function Remove-StringSpecialCharacter { <# .SYNOPSIS This function will remove the special character from a string.
🌐
RegexOne
regexone.com › lesson › excluding_characters
RegexOne - Learn Regular Expressions - Lesson 4: Excluding specific characters
For example, the pattern [^abc] will match any single character except for the letters a, b, or c. With the strings below, try writing a pattern that matches only the live animals (hog, dog, but not bog). Notice how most patterns of this type can also be written using the technique from the last lesson as they are really two sides of the same coin. By having both choices, you can decide which one is easier to write and understand when composing your own patterns.
🌐
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 character works. For others like $ or ^, using the special character doesn’t work.
🌐
Ablebits
ablebits.com › ablebits blog › excel › regex › regex to remove certain characters or text in excel
Regex to remove certain characters or text in Excel
August 22, 2023 - To remove all matches, the instance_num argument is not defined: ... To strip off certain characters from a string, just write down all unwanted characters and separate them with a vertical bar | which acts as an OR operator in regexes.