csharp replace characters in string that are invalid using regex

Code Example - csharp replace characters in string that are invalid using regex

                
                        string pattern = "[\\~#%&*{}/:<>?|\"-]";
string replacement = " ";

Regex regEx = new Regex(pattern);
string sanitized = Regex.Replace(regEx.Replace(input, replacement), @"\s+", " ");

This will replace runs of whitespace with a single space as well.