title: Javascript RegEx Remove Multiple words from string
body: <p>Using Javascript. (<em>note there is a similar <a href="https://stackoverflow.com/questions/21445022/remove-multiple-words-from-string-in-one-statement">post</a>, but the OP requested Java, this is for Javascript</em>)</p>
  
  <p>I'm trying to remove a list of words from an entire string without looping (preferably using Regular Expressions).</p>
  
  <p>This is what I have so far, and it removes some of the words but not all of them. Can someone help identify what I'm doing wrong with my RegEx function?</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>   //Remove all instances of the words in the array
    var removeUselessWords = function(txt) {
  
   var uselessWordsArray = 
          [
            "a", "at", "be", "can", "cant", "could", "couldnt", 
            "do", "does", "how", "i", "in", "is", "many", "much", "of", 
            "on", "or", "should", "shouldnt", "so", "such", "the", 
            "them", "they", "to", "us",  "we", "what", "who", "why", 
            "with", "wont", "would", "wouldnt", "you"
          ];
     
   var expStr = uselessWordsArray.join(" | ");
   return txt.replace(new RegExp(expStr, 'gi'), ' ');
    }
  
    var str = "The person is going on a walk in the park. The person told us to do what we need to do in the park";
    
    console.log(removeUselessWords(str));
  
  //The result should be: "person going walk park. person told need park."</code></pre>
  </div>
  </div>
  </p>