Skip to content

Instantly share code, notes, and snippets.

@feanz
Created October 31, 2013 17:10
Show Gist options
  • Save feanz/7253371 to your computer and use it in GitHub Desktop.
Save feanz/7253371 to your computer and use it in GitHub Desktop.
Remove Special Characters
protected static string RemoveAllSpecialCharacters(string input)
{
var r = new Regex("(?:[^a-z0-9 ]|(?<=['\"])s)", RegexOptions.IgnoreCase | RegexOptions.CultureInvariant | RegexOptions.Compiled);
return r.Replace(input, String.Empty);
}
protected static string RemoveSelectSpecialCharacters(string input)
{
var r = new Regex("[~#%&*{}:<>?|\".]", RegexOptions.IgnoreCase | RegexOptions.CultureInvariant | RegexOptions.Compiled);
return r.Replace(input, String.Empty);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment