Skip to content

Instantly share code, notes, and snippets.

@jtemplon
Created March 7, 2015 21:50
Show Gist options
  • Save jtemplon/89242303cffd43a822f3 to your computer and use it in GitHub Desktop.
Save jtemplon/89242303cffd43a822f3 to your computer and use it in GitHub Desktop.
def slugify(s):
"""Convert a string to a URL-friendly slug"""
slug = s.lower().strip()
slug = re.sub(r'[^a-zA-Z0-9\s]', '', slug)
slug = re.sub(r'\s+', '-', slug)
return slug
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment