title: Using simple angular filter to replace all occurences of certain strings in input string regardless of case and whitespaces
body: <p>On my website I have a commentary field, where people can write whatever they want. To prevent spam and unserious comments, I'm using an angular filter in this way:</p>
  
  <pre><code>&lt;span&gt;{{comment | mouthWash}}&lt;/span&gt;
  </code></pre>
  
  <p>The angular filter fetches an array containing banned words and scans through the input string and replaces all the occurences of the fetched words. The code for the filter is as below:</p>
  
  <pre><code>app.filter('mouthWash', function($http) {
  
    var badWords;
    $http.get('js/objects/bad-words.json').success(function (data) {
      badWords = data;
    });
  
    return function(input) {
      angular.forEach(badWords, function(word){
        var regEx = new RegExp(word);
        input = input.replace(regEx, "mooh");
      });
      return input;
    };
  
  });
  </code></pre>
  
  <p><strong>bad-words.json</strong> is something like this:</p>
  
  <pre><code>["fuck", "ass", "shit", etc...]
  </code></pre>
  
  <p>So as an example <code>&lt;span&gt;{{ "fuck this" | mouthWash}}&lt;/span&gt;</code> is outputted as <code>&lt;span&gt;mooh this&lt;/span&gt;</code></p>
  
  <p>This is working perfectly, except that I want it to ignore whitespaces, to make it more bullet proof. I do not have much experience with regex, so if anyone had a simple soloution to this, I would be really grateful.</p>