title: Javascript Clean URL Regex
body: <p>I am building a CMS news sections with a few fields but the ones notably needed for this question are the "Title" and "URL Reference" fields.  When a user enters in an article title I want Javascript/jQuery to replace the text from the Title field and create a "clean" URL fragment by removing any spaces and weird characters with a dash(-).</p>
  
  <p>e.g. </p>
  
  <p>Kris' FUN new Article (Title)</p>
  
  <p>kris-fun-new-article (URL Reference)</p>
  
  <p>Here is the code, but I can't seem to figure out how to replace multiple spaces and special characters</p>
  
  <pre>
  $('#title').keyup(function(){
      var ref = $(this).val().toLowerCase().replace('\ ','-');
      $('#reference').val(ref);
  });
  </pre>
  
  <p>Also, like in the title "Kris' FUN new Article" the regex should replace "Kris' "(quote and space) with "kris-"(one dash). Essentially recognize if there are two special characters beside one another and replace is with one dash. NOT like this "kris--fun-new-article".</p>
  
  <p>Thanks in advance</p>