Skip to content

Instantly share code, notes, and snippets.

@vquaiato
Created May 15, 2015 17:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vquaiato/09ee7621ce5db3b98c03 to your computer and use it in GitHub Desktop.
Save vquaiato/09ee7621ce5db3b98c03 to your computer and use it in GitHub Desktop.
.parameterize like in Python 3.4.x
def parameterize(string_to_clean, sep = '-'):
parameterized_string = unicodedata.normalize('NFKD', string_to_clean).encode('ASCII', 'ignore').decode()
parameterized_string = re.sub("[^a-zA-Z0-9\-_]+", sep, parameterized_string)
if sep is not None and sep is not '':
parameterized_string = re.sub('/#{re_sep}{2,}', sep, parameterized_string)
parameterized_string = re.sub('^#{re_sep}|#{re_sep}$', sep, parameterized_string, re.I)
return parameterized_string.lower()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment