title: Javascript regex pattern array with loop
body: <p>I have attempted to create a function that will replace multiple regular expression values from an array. This works if the array does not contain quotation marks of any kind, this is problematic when I want to use a comma in my pattern. So I've been trying to find an alternative way of serving the pattern with no luck. Any ideas?</p>
  
  <pre><code>function removeCharacters(str){
      //ucpa = unwanted character pattern array
      //var ucpa = [/{/g,/}/g,/--/g,/---/g,/-/g,/^.\s/];
      var ucpa = ["/{/","/}/","/--/","/---/","/-/","/^.\s/","/^,\s/"];
      for (var i = 0; i &lt; ucpa.length; i++){ 
          //does not work
          var pattern = new RegExp(ucpa[i],"g");
          var str = str.replace(pattern, " ");
      }
      return str;
  }
  </code></pre>
  
  <p>WORKING:</p>
  
  <pre><code>function removeCharacters(str){
      //ucpa = unwanted character pattern array
      var ucpa = [/{/g,/}/g,/--/g,/---/g,/-/g,/^.\s/,/^,\s/];
      for (var i = 0; i &lt; ucpa.length; i++){
          var str = str.replace(ucpa[i], " ");
      }
      return str;
  }
  </code></pre>
  
  <p>REFINED:</p>
  
  <pre><code>function removeCharacters(str){
      var pattern = /[{}]|-{1,3}|^[.,]\s/g;
      str = str.replace(pattern, " ");
      return str;
  }
  </code></pre>