title: JavaScript create regex programmatically
body: <p>I know that I can create a javascript replace like this:</p>
  
  <p><code>str = str.replace(/mytarget/g, 'some value');</code></p>
  
  <p>that will replace all the occurrences of the literal <code>mytarget</code>.
  However, I have a big array of words/phrases that I want to use in regex replace, and as regexps are just language elements (they are not wrapped in a string when declaring), I can't find a way to declare regexps programmatically unless I hard-code them. So if I have:</p>
  
  <p><code>var arr=['word', 'another', 'hello'];</code></p>
  
  <p>I want to produce:</p>
  
  <p><code>str = str.replace(/word/g, 'some value');</code></p>
  
  <p><code>str = str.replace(/another/g, 'some value');</code></p>
  
  <p><code>str = str.replace(/hello/g, 'some value');</code></p>
  
  <p>Please post an example that I can use regexps, as I'll be adding more expressions into the regexps such as whitespace etc. so I NEED it the regexp way. Finally, please don't offer using <code>eval</code>, I'm sure there is a better way.</p>