Skip to content

Instantly share code, notes, and snippets.

@kyya
Created August 15, 2018 12:56
Show Gist options
  • Select an option

  • Save kyya/9ea31c61b3b808bb5c89e0fabd797969 to your computer and use it in GitHub Desktop.

Select an option

Save kyya/9ea31c61b3b808bb5c89e0fabd797969 to your computer and use it in GitHub Desktop.
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