Python .parameterize equivalent to Rails .parameterize
import re
import unicodedata
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()
Written by Vinicius Quaiato
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Python
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#