Replacing special characters with dashes
<p>The user enters their text in <code>#title</code> and JQuery converts the string and places it in an input field named <code>#url</code>. The following code works:</p>

<pre><code>$('#title').on('keyup', function (e) {            
   e.preventDefault();
   var str = $(this).val();
   str = str.replace(/\W+/g, '-').toLowerCase();
   $('#url').val(str);
});
</code></pre>

<p>But here is the issue, If i enter <code>Big "Fish" Little "Fish"</code> JQuery will convert this to: <code>big-fish-little-fish-</code>. So the question is how do i remove the last - at the end. Could i use something like <code>before()</code> and then it will do the replacement?</p>