i am using the following regex [^a-zA-Z\d!-] pattern in c# to clean special characters from filename so i can pull basic information from it and build initial class property values from it
how ever no matter what i seem to do it wont clean the square brackets from the string according to regex builder it should be matching the square brackets but is not removing them when i run the replace operation
any help as to why would be greatly appreciated and a fix would be nice too =)
the code im using in c# is as follows:
var removeSpecChar = new Regex(@"[^a-zA-Z\d!-]");
msa = msa.Substring(0, msa.Length - 4);
removeSpecChar.Replace(msa, " ").Trim();
Didn’t try, but you really should escape the
-in characher sets:Also note that
\dis not equivalent to0-9, it matches any unicode digit (including arabic digits etc.). So you may want to change that if this isn’t your intention.