Refactor 2 regular expressions in Javascript into 1 statement I have the following code, which replaces " " &lt;-- Spaces with "-" &lt;-- Dash.
Because some of the title text will be returned with more spaces, it converts it into 3 dashes.  

Examples of Possible Titles:


"Hello&nbsp;&nbsp;World&nbsp;&nbsp;From&nbsp;&nbsp;Jquery"  &lt;--- Notice 2 Spaces between the words, not 1
"Main Title - Sub-Title or description here"  


I would like the above titles to be turned into:  


"Hello-World-From-Jquery" &lt;---- (Not "Hello--World--From--Jquery")
"Main-Title-Sub-Title-or-description-here" &lt;--- (Not "Main-Title---Sub-Title-or-desc...")


This is what I got so far, but its not ideal as you can see.
Example:

var dirty_url = ui.item.label;
var url = dirty_url.replace(/\s+/g,"-");
var url = url.replace(/---/g,"-");


So basically, I want to convert all spaces and illegal characters (Its for a url) to "-" to be used in a url. I only want a maximum of 1 dash between charactors.
Shouldn't this work:

var dirty_url = ui.item.label;
var url = dirty_url.replace(/[-\s]+/g,'-')


Or, for more thorough: 

var url = dirty_url.replace(/[-\s@#$%^&amp;*]+/g,'-') // etc...


Though at this point, you might just want to remove all non word characters:

var url = dirty_url.replace(/\W+/g,'-')