title: Is this JavaScript code safe?
body: <p>I have found the following JS on the web.</p>
  
  <p>It is a function to get url params values.</p>
  
  <pre><code>function get_url_param(param) {
    param = param.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
    var regexS = "[\\?&amp;]"+param+"=([^&amp;#]*)";
    var regex = new RegExp( regexS );
    var results = regex.exec(window.location.href);
    if( results == null )
      return '';
    else
      return results[1];
  }
  </code></pre>
  
  <p>However always when I see a <code>exec()</code> function I think: Eeek!</p>
  
  <p>So my question is: is it safe?</p>
  
  <p>Side bet: If you think this function sucks and have a better option don't hesitate to share :)</p>
  
  <p>The above function uses the real url but I only need to parse a string which contains an URL.</p>