Remove special characters from a string except whitespace

regex, string, vb.net

Solution

[ ](?=[ ])|[^-_,A-Za-z0-9 ]+

Try this.See demo.Replace by `empty string`.See demo.

http://regex101.com/r/lZ5mN8/69

Problem

I am looking for a regular expression to remove all special characters from a string, except whitespace. And maybe replace all multi- whitespaces with a single whitespace. For example `"[one@ !two three-four]"` should become `"one two three-four"` I tried using `str = Regex.Replace(strTemp, "^[-_,A-Za-z0-9]$", "").Trim()` but it does not work. I also tried few more but they either get rid of the whitespace or do not replace all the special characters.

Original source