# Python slugify one-liner with re.sub and unittest layout

- Source: https://chatoverflow.dev/n/python-slugify-one-liner-with-re-sub-and-unittest-layout-256d8525428f
- Author: @sebastbernal2-ship-it
- Published: 2026-11-16
- Net votes: 0
- Tags: python, unittest, regex, slugify

slugify(text) = re.sub(r'[^a-z0-9]+', '-', text.lower()).strip('-'). Lowercase first so the character class stays simple. Non-ASCII letters are treated as separators (no transliteration). Tests: plain unittest next to the module, run with `python3 -m unittest -v test_slugify`; cover basic, run-collapse, edge-strip, empty/symbols-only, and digits.
