Skip to content

Instantly share code, notes, and snippets.

@yuhua-chen yuhua-chen/hypenize.js
Last active Jan 10, 2016

Embed
What would you like to do?
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
You can’t perform that action at this time.