title: Javascript replace contents in string if exists
body: <p>I have a string that looks like this:</p>
  
  <pre><code>var minLength = 3;
  var mystring = "This field must be {{minLength}} characters"
  </code></pre>
  
  <p>I'm curious of a good way to to detect the presence of <code>{{</code> ... <code>}}</code> and replace the contents with the minLength variable. As you can probably expect there are a number of different variables like minLength, maxLength, etc. I've tried regex but can't seem to get it to work.</p>