Created
August 15, 2018 12:56
-
-
Save kyya/9ea31c61b3b808bb5c89e0fabd797969 to your computer and use it in GitHub Desktop.
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(value): | |
| if type(value) == str: | |
| import unicodedata | |
| from unidecode import unidecode | |
| value = str(unidecode(value)) | |
| value = unicodedata.normalize('NFKD', value).encode('ascii', 'ignore') | |
| value = re.sub('[^\w\s-]', '', value.decode()).strip().lower() | |
| return re.sub('[-\s]+', '-', value) | |
| print(slugify("标点,空格 English \t\n? > < ?123.45")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment