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
Discussions

removing all non-letter characters from a string? ((using regex))
This is very simple with regex. You just need to replace non-words (/\W/ig). So: var string = "lakjsdlkasjdlsaj@£$%^&*klajdlaskjds"; string.replace(/\W/ig, ""); --> "lakjsdlkasjdlsajklajdlaskjds" \w == words, \W == non words. You don't need a loop here as we're using /g which stands for global, so we replace every instance. And just incase I'm using /i as well which ignores the case. As it's regex you can just do /ig and the selectors will stack to ignore case and global. My favorite regex visualiser lives here: https://jex.im/regulex/#!embed=false&flags=ig&re=%5CW More on reddit.com
🌐 r/learnjavascript
10
4
September 28, 2015
How to find and remove non-alphanumeric character from a column - Oracle Forums
HiWe have a big table (900M rows), In this table for around 50K rows,the column (col) has got non-alphanumeric characters which shouldn't be as there was no validation at the app side.How could we str... More on forums.oracle.com
🌐 forums.oracle.com
January 25, 2018
Replace non-alphanumeric characters from string
For the navigation on my website, I created an index that is built from headline blocks. When you click on a headline in the index you scroll to that part in the page. One problem is that some headlines have non-alphanumeric content (like (, / or ?) that i don’t want to end up in the URL, ... More on forum.getkirby.com
🌐 forum.getkirby.com
2
0
May 17, 2023
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
🌐
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.
🌐
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.
🌐
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 - package main import ( "fmt" "regexp" ) var nonAlphanumericRegex = regexp.MustCompile(`[^a-zA-Z0-9 ]+`) func clearString(str string) string { return nonAlphanumericRegex.ReplaceAllString(str, "") } func main() { str := "Test@%String#321gosamples.dev ـا ą ٦" fmt.Println(clearString(str)) } ... This example works like the previous one, but by using a regular expression with Unicode categories, we also accept letters and numbers from alphabets other than English, such as Arabic. package main import ( "fmt" "regexp" ) var nonAlphanumericRegex = regexp.MustCompile(`[^\p{L}\p{N} ]+`) func clearString(str string) string { return nonAlphanumericRegex.ReplaceAllString(str, "") } func main() { str := "Test@%String#321gosamples.dev ـا ą ٦" fmt.Println(clearString(str)) }
🌐
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

Find elsewhere
🌐
Dot Net Office
dotnetoffice.com › 2022 › 08 › remove-non-alphanumeric-characters-from.html
Remove non-alphanumeric characters from a string in C# - Dot Net Office
August 10, 2022 - In this article, we will see how to Remove non-alphanumeric characters from a string in C# ... private static void RemoveNoAlphaChar() { string str = "dotnetoffice16@gmail.com"; str = Regex.Replace(str, "[^a-zA-Z0-9]", String.Empty); Console.WriteLine(str); Console.ReadLine(); } Code language: C# (cs)
🌐
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.’ ...
🌐
W3Schools
w3schools.com › php › php_regex.asp
PHP Regular Expressions
Regular expressions can be used to perform all types of text search and text replace operations.
🌐
Oracle
forums.oracle.com › ords › apexds › post › how-to-find-and-remove-non-alphanumeric-character-from-a-co-5744
How to find and remove non-alphanumeric character from a column - Oracle Forums
January 25, 2018 - HiWe have a big table (900M rows), In this table for around 50K rows,the column (col) has got non-alphanumeric characters which shouldn't be as there was no validation at the app side.How could we str...
🌐
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 - This is because the Replace method from the System.String class replaces straight-out strings, and it does not accept a RegEx pattern. Luckily, I can use the –Replace operator in Windows PowerShell to do the replacement. I want to replace any non-alphabetic character with a blank space in my output.
🌐
Kirby Forum
forum.getkirby.com › the cms › questions
Replace non-alphanumeric characters from string - Questions - Kirby Forum
May 17, 2023 - For the navigation on my website, I created an index that is built from headline blocks. When you click on a headline in the index you scroll to that part in the page. One problem is that some headlines have non-alphanumeric content (like (, / or ?) that i don’t want to end up in the URL, and that I’d like to replace with a ‘_’ I understood that a regular expressions like '/[^a-z0-9 ]/i' should work normally.
🌐
Baeldung
baeldung.com › home › java › java array › removing all non-alphabetic characters from string array in java
Removing All Non-alphabetic Characters From String Array in Java | Baeldung
November 18, 2024 - This approach is both flexible and easy to implement: public static String removeNonAlphabeticUsingRegex(String input) { return input.replaceAll("[^a-zA-Z]", ""); } We use regex to identify and remove non-alphabetic characters from the input string.
🌐
Makolyte
makolyte.com › csharp-remove-non-alphanumeric-characters-from-a-string
C# - Remove non-alphanumeric characters from a string | makolyte
January 26, 2025 - So with regex, you specify which characters you want, and then use the ^ operator to match everything but those characters. Here’s an example of specifying the Greek Unicode code point range: Regex.Replace(s, "[^Ͱ-Ͽ]", ""); Code language: C# (cs)
🌐
Splunk Community
community.splunk.com › t5 › Splunk-Search › Replace-non-alphanumeric-characters-in-a-multivalue-field › m-p › 676298 › highlight › true
Re: Replace non-alphanumeric characters in a multi... - Splunk Community
February 3, 2024 - I have a MV field and am iterating through it and using a regex to create multiple capture groups, then create a new field using some those capture groups. That new field is colon separated. Currently, I noticed that within my 3rd capture group, the values within the MV field can sometimes have non-alphanumeric characters which is causing the regex to not match (due to the regex being [\w\s]).
🌐
Interview Kickstart
interviewkickstart.com › home › blogs › learn › how to remove all non-alphanumeric characters from a string in java?
Remove Non-Alphanumeric Characters from a String in Java
December 19, 2024 - If it is non-alphanumeric, we replace all its occurrences with empty characters using the String.replace() method.
🌐
Irt
irt.org › script › 1583.htm
Q1583 How can I replace all non alphanumeric characters from a string?
<script language="JavaScript"><!-- var temp = new String('This is a test string... So??? What...'); document.write(temp + '<br>'); temp = temp.replace(/[^a-zA-Z 0-9]+/g,''); document.write(temp + '<br>'); //--></script>
🌐
Microsoft Learn
learn.microsoft.com › bs-latn-ba › dotnet › standard › base-types › how-to-strip-invalid-characters-from-a-string
How to: Strip Invalid Characters from a String - .NET | Microsoft Learn
In this case, CleanInput strips out all nonalphanumeric characters except periods (.), at symbols (@), and hyphens (-), and returns the remaining string. However, you can modify the regular expression pattern so that it strips out any characters that should not be included in an input string. using System; using System.Text.RegularExpressions; public class Example { static string CleanInput(string strIn) { // Replace invalid characters with empty strings. try { return Regex.Replace(strIn, @"[^\w\.@-]", "", RegexOptions.None, TimeSpan.FromSeconds(1.5)); } // If we timeout when replacing invalid characters, // we should return Empty.