title: Regex to replace space with dash in jQuery
body: <p>I have the following code, which populates a field upon typing into another...</p>
  
  <pre><code>$('#title').bind('keyup keypress blur', function() 
  {  
  
      var myStr = $(this).val()
          myStr=myStr.toLowerCase();
          myStr=myStr.replace(/ /g,"-");
          myStr=myStr.replace(/[^a-zA-Z0-9\.]+/g,"");
          myStr=myStr.replace(/\.+/g, "-");
  
  
      $('#filename').val(myStr); 
  });
  </code></pre>
  
  <p>The code works to remove any none alphanumeric characters, however I want it to replace spaces with a '-' dash.</p>
  
  <p>If i change the dash to a period '.' this works, not sure why or how to remedy it? Regex confuses me.</p>
  
  <p><a href="http://jsfiddle.net/2a4gx/" rel="noreferrer"><strong>JSFIDDLE here</strong></a></p>
  
  <p>Can anyone point me in the right direction?</p>
  
  <p><em><strong>UPDATE</em></strong></p>
  
  <p>Just got it to work as required using this...</p>
  
  <pre><code>&lt;script&gt;
  $('#title').bind('keyup keypress blur', function() 
  {  
  
      var myStr = $(this).val()
          myStr=myStr.toLowerCase();
          myStr=myStr.replace(/[^a-zA-Z0-9 ]+/g,"");
          myStr=myStr.replace(/\s+/g, "-");
  
  
      $('#filename').val(myStr); 
  });
  &lt;/script&gt;
  </code></pre>