Regex Expressions for all non alphanumeric symbols
If you want to match non-alphanumeric symbols then just use \W|_
.
Regex pattern = new Regex(@"\W|_");
This will match anything except 0-9 and a-z. Information on the \W
character class and others available here (c# Regex Cheet Sheet).
- https://www.mikesdotnetting.com/article/46/c-regular-expressions-cheat-sheet
You could also avoid regular expressions if you want:
return s.Any(c => !char.IsLetterOrDigit(c))