title: Replace string with array
body: <p>I have strings which before processing (translate) have to be replaced, then after processing (translation done) replaced again.</p>
  
  <pre><code> var str = 'BUY [[Manufacturer]] [[Name]] cheap or get other [[Categories]] from [[Storename]] &lt;i class="fa fa-check"&gt;&lt;/i&gt; Thousands of satisfied customers.';
  </code></pre>
  
  <p>So I first reference them in an array with:</p>
  
  <pre><code>var res = str.match(/\[\[.*?\]\]/gm);
  </code></pre>
  
  <p>then I replace them:</p>
  
  <pre><code>var placeholder_string = str.replace(/\[\[.*?\]\]/gm,"|");
  </code></pre>
  
  <p>then it will be processed (in this case translated).</p>
  
  <p>Now I want to reverse back all placeholders "|" with the array <code>res</code>.</p>
  
  <p>I know I can take a function in the replace argument from <code>replace()</code>, but please help me how to achieve that efficiently.</p>
  
  <pre><code>var revert_string = placeholder_string.replace("|", myfunc());
  </code></pre>
  
  <p>or is there a better way??</p>