I\'m completely incapable of regular expressions, and so I need some help with a problem that I think would best be solved by using regular expressions.
I have list
It really depends on your definition of special characters. I find that a whitelist rather than a blacklist is the best approach in most situations:
tmp = Regex.Replace(n, "[^0-9a-zA-Z]+", "");
You should be careful with your current approach because the following two items will be converted to the same string and will therefore be indistinguishable:
"TRA-12:123"
"TRA-121:23"
tmp = Regex.Replace(n, @"\W+", "");
\w
matches letters, digits, and underscores, \W
is the negated version.
You can use:
string regExp = "\\W";
This is equivalent to Daniel's "[^a-zA-Z0-9]
"
\W matches any nonword character. Equivalent to the Unicode categories [^\p{Ll}\p{Lu}\p{Lt}\p{Lo}\p{Nd}\p{Pc}]
.