string username = Regex.Replace(_username, @"(\s+|@|&|'|\(|\)|<|>|#)", "");
Answer from Mithilesh Gupta on Stack Overflow
Discussions

Regex remove all special characters except numbers?
Learn more about Collectives ... Bring the best of human thought and AI automation together at your work. Explore Stack Internal ... I would like to remove all special characters (except for numbers) from a string. More on stackoverflow.com
🌐 stackoverflow.com
Using regex to remove non-alphabetical characters in a string.
if a pattern matches things you want to keep, like "all letters": [a-zA-Z] you can invert it with "^" to make it "not" those things: [^a-zA-Z] also, there are (depending on which language and which regex variant you're using) shortcuts like \s = a space (or tab or newline or...) \S = not a space \w = a word type character (i.e. a-z A-Z 0-9 etc) \W = not a word type character \d = a number \D = not a number More on reddit.com
🌐 r/learnprogramming
7
1
July 24, 2021
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
🌐 forum.uipath.com
11
8
January 27, 2020
Regex to remove special characters
This gets rid of all characters that are not special letters, spaces or numbers. ... Remove any characters from the incoming field that are outside of the range of ASCII values from "space" to "~". ... Below is the ASCII table where you can see the range 32(space) - 126(~), so any characters that fall other than this range will get replaced with '' ... @binu_acs that's actually very interesting to read I will definitely read more into regex ... More on community.alteryx.com
🌐 community.alteryx.com
January 5, 2023
🌐
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 chara…
🌐
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!!!

🌐
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
🌐
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. ... Have your text with unwanted characters ready. ... Paste your data or load the file into the input area. ... Click on the "Options" and select the desired character set you want to keep.
Find elsewhere
🌐
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.
🌐
W3Resource
w3resource.com › csharp-exercises › re › csharp-re-exercise-8.php
C# - Remove special characters from a given text
August 25, 2025 - using System; using System.Text.RegularExpressions; namespace exercises { class Program { // Main method - entry point of the program static void Main(string[] args) { // Define and initialize test strings string text = "AA@%^&CC"; Console.WriteLine("Original string: " + text); // Call the test method and display the modified string Console.WriteLine("New string: " + test(text)); // Update the test string text = "Python"; Console.WriteLine("Original string: " + text); // Call the test method and display the modified string Console.WriteLine("New string: " + test(text)); // Update the test stri
🌐
Ablebits
ablebits.com › ablebits blog › excel › regex › regex to remove certain characters or text in excel
Excel Regex to remove certain characters or text from strings
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.
🌐
YouTube
youtube.com › watch
How to Remove All Special Characters from String with a single line of code. - YouTube
Enjoy the videos and music you love, upload original content, and share it all with friends, family, and the world on YouTube.
Published   April 6, 2022
🌐
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 - We use Character1 & Character2 ... each. Special characters like backslashes need to be ‘escaped’ by preceding them with another backslash as the Regex string uses a backslash as a functional character....
🌐
Reddit
reddit.com › r/csharp › removing special characters from a string.
r/csharp on Reddit: Removing special characters from a string.
April 27, 2016 -

I got this from codewars. I used string.Replace() and an array to solve it but the top voted answer seemed more elegant. Problem is, I don't understand all of it.

public static string removeNoise(string equation) { return Regex.Replace(equation,@"[^a-zA-Z0-9\t. ?!]", ""); }

The problem is to remove any of these characters from a string: %$&/#·@|º\ª

The given parameter to test the method is "h%e&·%$·llo w&%or&$l·$%d".

After reading some msdn, here is what I think I understand so far:

  1. It is using the Regex.Replace(string, string, string) overloaded method.

  2. The first part of the solution says replace any characters that are not a to z, A to Z and 0 to 9 with an empty string literal.

  3. The "." says to remove any "." characters.

What I don't understand:

  1. What is the significance of the brackets []?

  2. I don't see any tab characters in the given parameter. Why \t? Better yet, is \t a character that looks like multiple space characters?

  3. Why the space between "." and ?!

  4. What does ?! mean? msdn says "Zero-width negative lookahead assertion." It gives the example \b(?!un)\w+\b matches "sure", "used" in "unsure sure unity used". I can sort of infer what it means but I'm still not sure.

A minor detail: Lastly, I see conflicting results on system performance for using string.Replace(), Regex.Replace(), and stringbuild.Replace(). Articles from 2008/2009 say string.Replace() is faster but others say that Regex.Replace() is faster if performing more complicated tasks. Any recent update to this. This one isn't as key to my learning but would be interesting to note.

Edit: Resolved! Thanks all. Next step understand the stringbuilder.Replace() version of this.

Edit 2: For reference, my original solution was to place each special character in an array as a string[] and use a foreach loop with string.Replace(). Also, I found a stringbuild.Replace() version that's pretty cool. http://stackoverflow.com/questions/1120198/most-efficient-way-to-remove-special-characters-from-string

Edit 3: I posted an issue on the codewars discussion and I'm waiting for feedback because I found something else that should work (according to https://msdn.microsoft.com/en-us/library/az24scfc(v=vs.110).aspx):

return Regex.Replace(equation, @"[^\w ]", "");

It says to replace all non-alphanumeric characters or spaces with a blank. It works in Visual Studio 2015 but codewars check denies me (You failed the test for '%$&/#?@|??'.).

🌐
Regex101
regex101.com › r › gJ6oZ6 › 1
regex101: Remove all special chars from string
An explanation of your regex will be automatically generated as you type. Detailed match information will be displayed here automatically. Search reference · All Tokens · Common Tokens · General Tokens · Anchors · Meta Sequences · Quantifiers · Group Constructs · Character Classes ·
🌐
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.
🌐
Mozilla
developer.mozilla.org › en-US › docs › Web › JavaScript › Guide › Regular_expressions
Regular expressions - JavaScript - MDN Web Docs
/a\*b/ and new RegExp("a\\*b") create the same expression, which searches for "a" followed by a literal "*" followed by "b". The RegExp.escape() function returns a new string where all special characters in regex syntax are escaped.
🌐
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”