title: Replacing parameter in URL with regex
body: <p>I want to replace ":id" in url string with particular id e.g. 54 My question would be is it enough to use "/(:id)/i" for replacing this parameter, or I should use something more complex? Thanks</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var url = "http://www.test.com/api/person/:id/details"
  var str = url.replace(/(:id)/i, 54);</code></pre>
  </div>
  </div>
  </p>
  
  <p>Updated:</p>
  
  <p>I just realized that it would be great to have a function which would be able to replace multiple values in URL. Example:</p>
  
  <pre><code>function replaceParametersInUrl(url, params) {
    var regex = new RegExp(Object.keys(params).join('|'), 'gi');
      return url.replace(regex, function(matched) {
      return params[matched];
    });
  }
  
  console.log(replaceParametersInUrl("api/person/:userId/items/:itemId",  {userId: 56, itemId: 1}));
  </code></pre>
  
  <p>The problem with this solution is that it replaces just userId and itemId strings without ":". How I can achieve that it would replace those strings including ":"?</p>