Replace [^a-zA-Z0-9]
with an empty string.
string str = "This-is-my+++***RegexPattern&Text"; Regex rgx = new Regex("[^a-zA-Z0-9]"); str = rgx.Replace(str, ""); OUTPUT: ThisismyRegexPatternText
If you want to add an exception then you should add this character like this to the regex pattern (let’s assume you wish to exclude the ampersand):
[^a-zA-Z0-9 &]
string str = "This-is-my+++***RegexPattern&Text"; Regex rgx = new Regex("[^a-zA-Z0-9 &]"); str = rgx.Replace(str, ""); OUTPUT: ThisismyRegexPattern&Text