How do I remove all non alphanumeric characters from a string except dash and space characters?

13 s
13

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

Regex rgx = new Regex("[^a-zA-Z0-9 -]");
str = rgx.Replace(str, "");

Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *