15 lines
298 B
Python
15 lines
298 B
Python
|
|
import re
|
|
|
|
|
|
def slugify(input : str) -> str:
|
|
s = input.lower()
|
|
s = re.sub(r'\s+', '_', s)
|
|
s = re.sub(r'[^a-z0-9_]+', '', s)
|
|
s = re.sub(r'_+', '_', s)
|
|
s = s.strip('_')
|
|
if not s:
|
|
s = 'buttonplus'
|
|
while len(s) > 1 and s[0].isdigit():
|
|
s = s[1:]
|
|
return s |