Created
December 7, 2021 09:35
-
-
Save entirelymagic/1611de2294255bd557aa7eb96300800e to your computer and use it in GitHub Desktop.
Converts a string to a URL-friendly slug.
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
import re | |
def slugify(s): | |
s = s.lower().strip() | |
s = re.sub(r'[^\w\s-]', '', s) | |
s = re.sub(r'[\s_-]+', '-', s) | |
s = re.sub(r'^-+|-+$', '', s) | |
return s |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment