Skip to content

Instantly share code, notes, and snippets.

@jzazove
Created December 15, 2011 03:54
Show Gist options
  • Save jzazove/1479763 to your computer and use it in GitHub Desktop.
Save jzazove/1479763 to your computer and use it in GitHub Desktop.
URL Friendly Javascript Regex
/* 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"
@andresmafra
Copy link

thanks! 👍

@AlpeshKatariya
Copy link

Great work I'm very appericate

@jayllellis
Copy link

Works like a charm. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment