Created
December 15, 2011 03:54
-
-
Save jzazove/1479763 to your computer and use it in GitHub Desktop.
URL Friendly Javascript Regex
This file contains 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 to urlify a string */ | |
var urlify = function(a){return a.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "-").replace(/^-+|-+$/g, '')}; | |
/* usage example */ | |
var str_a = "* The Best Wallpaper Magazine in the . ? & world! : Rjer9238131 & "; | |
urlify(str_a) | |
/* returns */ | |
"the-best-wallpaper-magazine-in-the-world-rjer9238131" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Works like a charm. Thanks!