Skip to content

Instantly share code, notes, and snippets.

@yuhua-chen
Last active January 10, 2016 06:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yuhua-chen/896e46d2a382fff70fb9 to your computer and use it in GitHub Desktop.
Save yuhua-chen/896e46d2a382fff70fb9 to your computer and use it in GitHub Desktop.
Replace special chars with hyphen.
function hyphenize(string) {
string = string.replace(/[^A-Za-z0-9\. -]/g, '');
return string.replace(/ */g, '-');
}
var str = "Nike The Future One / Interactive Setting"
hyphenize(str)
// "Nike-The-Future-One-Interactive-Setting"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment