title: JavaScript replace() regex by index number
body: <p>I have the following string and regex:</p>
  
  <pre><code>var string = "Dear [to name], [your name] has decided to share this [link]"; 
  var patt = /\[+[A-Za-z0-9]+\]/;
  </code></pre>
  
  <p>I want to be able to change each of the bracketed variables with dynamic input. How would I use <code>match()</code> or <code>replace()</code> to target the 1st, 2nd and 3rd occurrences of this regex?</p>
  
  <p><strong>EDIT:</strong> At the moment if I do something like <code>document.write(body.match(patt));</code> it will match only the last one [link]</p>
  
  <p><strong>EDIT:</strong> The entire string is take from the value of a text box. The values for each of the brackets are taken from other text inputs and need to be inserted into the string before the text is put back into the text box.</p>