title: JavaScript REGEX Match all and replace
body: <p>I am coding a simple templating function in javascript.</p>
  
  <p>I have my template loading fine, now is the part when I need to parse the content to the placeholders.</p>
  
  <p>an example of a template is: </p>
  
  <pre><code>{{name}} is {{age}}
  </code></pre>
  
  <p>These are dynamic, so ideally I want to use regex to match and replace the placeholders based on their names, e.g.</p>
  
  <p>{{name}} is to be replaced by content loaded in a javascript array, e.g. </p>
  
  <pre><code>data.name
  
  data.age
  </code></pre>
  
  <p>This is my regex: <code>/\{\{(.*?)\}\}/</code></p>
  
  <p>This is working fine, but after a lot of searching I can't find a defined way of iterating through every regex match.</p>
  
  <p>Thanks in advance</p>