Replace [^a-zA-Z0-9 -] with an empty string.

Regex rgx = new Regex("[^a-zA-Z0-9 -]");
str = rgx.Replace(str, "");
Answer from Amarghosh on Stack Overflow
🌐
Reddit
reddit.com › r/learnjavascript › removing all non-letter characters from a string? ((using regex))
r/learnjavascript on Reddit: removing all non-letter characters from a string? ((using regex))
September 28, 2015 -

I am currently trying this two different ways and they aren't working - I'm checking the input value and running this every time a key is pressed:

input.replace(/[^a-zA-z]/, "");

and

for(var i = 0; i < input.length; i++){
	   if( input[i] ==  /[^a-zA-z]/g){
	   	console.log("input " + input[i] + " is not a letter!");
	    	input.replace(input[i], "");
	   }
	}

jsfiddle here

Discussions

Python regex to replace any characters that are not either letters or white space - Stack Overflow
However, the official documentation ...g/3/howto/regex.html · So I see now that my code says ~find anything that is not a letter and not in the above set of special characters and replace it with ''. So is there a way to retain whitespace but remove the other special characters? ... A-z - It includes all the character from ascii table starting from A to z, which also has non alphabetical ... More on stackoverflow.com
🌐 stackoverflow.com
RegEx to remove all non alphanumeric characters
Could someone please show me how to use some simple RegEx to do the following please: "String with spaces, punctuation; and numbers (22)" -> "Stringwithspacespunctuationandnumbers22" The only characters I want to retain are letters a-z (case doesn't matter) and numbers 0 to 9. I'm working with ... More on community.alteryx.com
🌐 community.alteryx.com
December 1, 2016
neovim - Regex for any character that is not alphanumeric, whitespace, or a doublequote - Vi and Vim Stack Exchange
I expect this to select all non-alphanumeric characters: [^\w] Instead it selects all non-w's. This is the regex I would use in JavaScript, Python etc.: [^\w\s"] How can I write this so that... More on vi.stackexchange.com
🌐 vi.stackexchange.com
November 2, 2020
What is the regex pattern to remove all characters except numbers and letters?
I am not good with regex. What is the pattern to remove all spaces, tabs, dashes, and all other non- number or letter characters easily from a string? More on forum.bubble.io
🌐 forum.bubble.io
2
1
January 23, 2020
🌐
gosamples
gosamples.dev › tutorials › remove non alphanumeric characters from a string in go
🧽 Remove non-alphanumeric characters from a string in Go
May 19, 2022 - This is a classic example of removing non-alphanumeric characters from a string. First, we compile our regular expression that matches any character other than an English letter, number, or space. Then, we use the Regexp.ReplaceAllString() method to replace the matched non-alphanumeric characters ...
🌐
Medium
medium.com › @shamzaibrahim7 › three-techniques-to-remove-non-alphanumeric-characters-for-palindrome-problem-9ab7a78d8490
Three Techniques to Remove Non-Alphanumeric Characters for Palindrome Problem | by Syed Hamza | Medium
March 27, 2023 - To use regular expressions to remove non-alphanumeric characters, we can define a regular expression pattern that matches all non-alphanumeric characters, and then use the re.sub() function to replace all matches with an empty string.
🌐
Microsoft
devblogs.microsoft.com › dev blogs › scripting blog [archived] › powertip: replace non-alphabetic characters in string
PowerTip: Replace Non-Alphabetic Characters in String - Scripting Blog [archived]
February 18, 2019 - How can I use Windows PowerShell to replace a string that contains non-alphabetic characters (such as commas and periods)? Use the –Replace operator, and specify a regex pattern ‘[^a-zA-Z]’, for example: $a = ‘Never a foot too far, even.’ ...
🌐
YouTube
youtube.com › excelmoments
REGEX - Extract all Alphabets/Remove all non-alphabets #excel - YouTube
In this video, we show simple REGEX expressions to remove all special characters or in essence remove or no-alphabet characters#excel #regex #exceltips
Published   July 16, 2024
Views   525
🌐
Bobby Hadz
bobbyhadz.com › blog › javascript-remove-characters-not-match-regex
Replace/Remove characters that Don't match Regex in JS | bobbyhadz
In other words, we replace multiple ... of a character that doesn't match the regex with a specific character, remove the plus + symbol from the regex....
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › javascript-program-to-remove-non-alphanumeric-characters-from-a-string
JavaScript Program to Remove Non-Alphanumeric Characters from a String - GeeksforGeeks
July 23, 2025 - Regular expressions offer a concise way to match and remove non-alphanumeric characters. We can use the replace() method with a regular expression to replace all non-alphanumeric characters with an empty string.
🌐
GeeksforGeeks
geeksforgeeks.org › java › how-to-remove-all-non-alphanumeric-characters-from-a-string-in-java
How to remove all non-alphanumeric characters from a string in Java - GeeksforGeeks
July 15, 2025 - The string can be easily filtered using the ReGex [^a-zA-Z0-9 ]. ... // Java program to remove non-alphanumeric // characters from a string class GFG { // Main driver method public static void main(String args[]) { // Input string String str1 = "@!Geeks-for'Geeks, 123"; str1 = str1.replaceAll("[^a-zA-Z0-9]", ""); System.out.println(str1); } }
🌐
Baeldung
baeldung.com › home › kotlin › kotlin strings › removing all non-alphanumeric characters in kotlin
Removing All Non-Alphanumeric Characters in Kotlin | Baeldung on Kotlin
March 19, 2024 - val text = "This notebook costs 2000€ (including tax)" val nonAlphaNum = "[^a-zA-Z0-9]".toRegex() val justAlphaNum = text.replace(nonAlphaNum, "") assertEquals("Thisnotebookcosts2000includingtax", justAlphaNum) As shown above, we’re removing the euro sign, parentheses, and space characters. Unfortunately, the same simple regex won’t recognize letters and numbers in different languages.
🌐
Bubble
forum.bubble.io › need help
What is the regex pattern to remove all characters except numbers and letters? - Need help - Bubble Forum
January 23, 2020 - I am not good with regex. What is the pattern to remove all spaces, tabs, dashes, and all other non- number or letter characters easily from a string?
🌐
Bobby Hadz
bobbyhadz.com › blog › javascript-remove-non-alphanumeric-characters-from-string
Remove all non-alphanumeric Characters from a String in JS | bobbyhadz
The removeNonAlphanumeric() function takes a string as a parameter and removes all non-alphanumeric characters from the string. You can also use the \W special character to shorten your regex and remove all non-alphanumeric characters from a string.
🌐
UiPath Community
forum.uipath.com › help
How to replace any character that is not a letter or a digit with an underscore in a string? - Help - UiPath Community Forum
March 14, 2019 - Hi Guys, Just wondering if there is a way to detect and replace in a string any character different than a number or letter? any idea?
🌐
Microsoft
devblogs.microsoft.com › dev blogs › scripting blog [archived] › weekend scripter: remove non-alphabetic characters from string
Weekend Scripter: Remove Non-Alphabetic Characters from String - Scripting Blog [archived]
February 18, 2019 - Blog post, the trick to solving the problem of removing non-alphabetic characters from a string is to create two letter ranges, a-z and A-Z, and then use the caret character in my character group to negate the group—that is, to say that I ...