#283 · Regular expressions · Intermediate · 65 XP · about 12 min
Blogs turn a post's title into a short, readable piece of its web address called a slug: "Crème Brûlée: 10 Tips!" becomes creme-brulee-10-tips. Write slugify(title) that builds a slug with these steps, in this order:
unicodedata.normalize('NFKD', title) splits an accented letter such as é into a plain letter followed by a separate accent mark, and unicodedata.combining(ch) is not 0 for those marks, so drop every character for which it is not 0.' and ’, so "Don't" becomes "dont".-.- from the start and the end.If nothing is left, the slug is the empty string.
slugify('Hello, World!') # returns 'hello-world' slugify(' Crème Brûlée: 10 Tips! ') # returns 'creme-brulee-10-tips' slugify("Don't Stop -- Café Edition") # returns 'dont-stop-cafe-edition' slugify('!!!') # returns ''
title has at most 100,000 characters.First solves only, ranked by stars and then time.