title: How to replace all given characters?
body: <p>I'm trying to write a method that <em>replaces all occurrences</em> of the characters in the input array (<code>charsToReplace</code>) with the <code>replacementCharacter</code> using regex. The version I have written <em>does not work</em> if the array contains any characters that <em>may change</em> the meaning of the regex pattern, such as <code>']'</code> or <code>'^'</code>.</p>
  
  <pre><code>public static string ReplaceAll(string str, char[] charsToReplace, char replacementCharacter)
  {
      if(str.IsNullOrEmpty())
      {
          return string.Empty;
      }
  
      var pattern = $"[{new string(charsToReplace)}]";
      return Regex.Replace(str, pattern, replacementCharacter.ToString());
  }
  </code></pre>
  
  <p>So <code>ReplaceAll("/]a", {'/', ']' }, 'a')</code> should return <code>"aaa"</code>.</p>