Reputation: 149
I am trying to filter out anything other than letters, numbers, space,(,),/,-,and a .. This is the code I am using. It does some filtering but allows quotes, semicolons, and a few other things through. Where did I go wrong?
filteredst = Regex.Replace(st, @"^[a-zA-Z0-9 .()/-]+", String.Empty);
Thanks for your time.
Upvotes: 1
Views: 90
Reputation: 70732
You need to place the negation operator inside of your class instead of applying it as the beginning of string anchor.
Regex.Replace(st, @"[^a-zA-Z0-9 .()/-]+", String.Empty);
Example:
String s = @"foo/bar ''''(baz.) """"12-34;:;;!%$@";
String r = Regex.Replace(s, @"[^a-zA-Z0-9 .()/-]+", String.Empty);
Console.WriteLine(r); //=> "foo/bar (baz.) 12-34"
Upvotes: 2