<p>So I was writing some code today that basically looks like this:</p>

<pre><code>string returnString = s.Replace("!", " ")
            .Replace("@", " ")
            .Replace("#", " ")
            .Replace("$", " ")
            .Replace("%", " ")
            .Replace("^", " ")
            .Replace("*", " ")
            .Replace("_", " ")
            .Replace("+", " ")
            .Replace("=", " ")
            .Replace("\", " ")
</code></pre>

<p>Which isn't really nice. I was wondering if there's a regex or something that I could write that would replace all the calls to the <code>Replace()</code> function?</p>

You can use
Regex.Replace()
. All of the characters can be placed between square brackets, which matches any character between the square brackets. Some special characters have to be escaped with backslashes, and I use a @verbatim string here, so I don't have to double-escape them for the C# compiler. The first parameter is the input string and the last parameter is the replacement string.
```
```
var returnString = Regex.Replace(s,@"[!@#\$%\^*_\+=\\]"," ");
```
```