Last active
January 10, 2016 06:41
-
-
Save yuhua-chen/896e46d2a382fff70fb9 to your computer and use it in GitHub Desktop.
Replace special chars with hyphen.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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