title: javascript regex - remove a querystring variable if present
body: <p>I need to rewrite a querysting using javascript.
  First I check to see if the variable is present, if it is I want to replace it with a new search term. If it is not present then I just add the new variable</p>
  
  <p>I'm able to get it to work with simple terms like hat, ufc hat
  whitespaces are %20, so ufc hat is really ufc%20hat</p>
  
  <p>I run into problem with terms like make-up, hat -baseball, coffee &amp; tea, etc..</p>
  
  <p>What is the proper regex for this?</p>
  
  <p>Below is my code, which doesn't work.</p>
  
  <pre><code>var url = String(document.location).split('?');
  querystring = url[1];
  if(querystring.match(/gbn_keywords=/)!=null)
  querystring=querystring.replace(/gbn_keywords=[a-zA-Z0-9%20.]+/,"gbn_keywords="+term);
  else
  querystring=querystring+"&amp;gbn_keywords="+term;
  </code></pre>