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
๐ŸŒ
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 - Here is an example of how to use re.sub to replace all occurrences of the pattern "dog" with the replacement string "cat" in a string: ... Another way to remove non-alphanumeric characters is by checking the ASCII value of each character in the given phrase. If the ASCII value of a character is between 48 and 57 (inclusive) or between 97 and 122 (inclusive), it is an alphanumeric character.
๐ŸŒ
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 - We will explore all the above methods along with their basic implementation with the help of examples. 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.
Discussions

Replace all non alphanumeric characters, new lines, and multiple white space with one space
I'm looking for a neat regex solution to replace All non alphanumeric characters All newlines All multiple instances of white space With a single space For those playing at home (the following d... More on stackoverflow.com
๐ŸŒ stackoverflow.com
python - Replace all non-alphanumeric characters in a string - Stack Overflow
Short example re.sub(r'\W+', '_', 'bla: bla**(bla)') replaces one or more consecutive non-alphanumeric characters by an underscore. ... Save this answer. ... Show activity on this post. Regex to the rescue! More on stackoverflow.com
๐ŸŒ stackoverflow.com
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
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
๐ŸŒ
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 ... than an English letter, number, or space. Then, we use the Regexp.ReplaceAllString() method to replace the matched non-alphanumeric characters with the empty string ""....
๐ŸŒ
Kirby Forum
forum.getkirby.com โ€บ the cms โ€บ questions
Replace non-alphanumeric characters from string - Questions - Kirby Forum
May 17, 2023 - 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 ...
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 ... 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: ...
๐ŸŒ
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 ยท // Java program to remove non-alphanumeric // characters from a string class GFG { // Main driver method public static void main(String args[]) { // Input string String ...
๐ŸŒ
Gopher Coding
gophercoding.com โ€บ remove-non-alphanumeric-chars
Remove All Non-Alphanumeric Characters ยท Gopher Coding
April 2, 2023 - <p>We often need to remove symbols and special characters from the strings we&rsquo;re using (<em>especially with currency!</em>). This post shows how you can keep the letters and numbers, but remove any punctuation, symbols, grammar, etc. For example, if a user types in &ldquo;$1,000&rdquo; you can turn it into &ldquo;1000&rdquo;.</p> <p>We use the <code>regexp</code> package to do this, first building a regex with <code>.Compile()</code> then running the string through that regex with <code>.ReplaceAllString()</code>. Finally with display and compare both strings.</p>
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ php โ€บ how-to-remove-non-alphanumeric-characters-in-php
How to remove non-alphanumeric characters in PHP? - GeeksforGeeks
October 10, 2018 - GeeksforGeeks2018 Method 2: The regular expression '/[^a-z0-9 ]/i' matches all the non-alphanumeric characters and replace them with ' ' (null string). $str = preg_replace( '/[^a-z0-9 ]/i', '', $str); In the regular expression: ... a-z: It is ...
๐ŸŒ
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.โ€™ ...
๐ŸŒ
xjavascript
xjavascript.com โ€บ blog โ€บ remove-not-alphanumeric-characters-from-string
How to Remove Non-Alphanumeric Characters from a String: Complete Regex Solutions and Examples โ€” xjavascript.com
The negation [^\w] will match non-alphanumeric characters excluding underscores: ... Below are examples in popular languages to implement both patterns. Weโ€™ll use the input string: input_string = "Hello! This is a test: 123_45#" const input = "Hello! This is a test: 123_45#"; const cleaned = input.replace(/[^a-zA-Z0-9]/g, ""); console.log(cleaned); // Output: "HelloThisisatest12345" /[^a-zA-Z0-9]/g...
๐ŸŒ
Regex101
regex101.com โ€บ r โ€บ jI5hK6 โ€บ 1
regex101: Remove Non-Alphanumeric Characters
An explanation of your regex will be automatically generated as you type.