mirror of
https://github.com/sstent/foodplanner.git
synced 2026-01-25 19:21:37 +00:00
12 lines
433 B
Python
12 lines
433 B
Python
import re
|
|
|
|
def slugify(s):
|
|
"""
|
|
Slugifies a string, converting spaces and non-alphanumeric characters to hyphens.
|
|
"""
|
|
s = s.lower()
|
|
s = re.sub(r'[^a-z0-9\s-]', '', s) # Remove all non-alphanumeric characters except spaces and hyphens
|
|
s = re.sub(r'[-\s]+', '-', s) # Replace spaces and hyphens with a single hyphen
|
|
s = s.strip('-') # Remove leading/trailing hyphens
|
|
|
|
return s |