Slugify Text
Finds runs of non-alphanumeric characters so they can be replaced with hyphens.
Use with a lowercase transform and trim step to turn ordinary text into URL-friendly slugs.
regexslugtext
Find
[^a-z0-9]+
Replace
-
Find (regex)
[^a-z0-9]+
Replace (text)
-
This replacement is one step in slug generation. Lowercase the input, replace matching runs, and trim leading or trailing hyphens afterward.
Order matters: lowercase first, or accented and uppercase characters survive into the result. The pattern is ASCII-only, so strip diacritics (or transliterate) before replacing, and remember a run like " - " collapses into a single hyphen, which is usually what you want.
Common mistakes
- Dropping meaningful non-Latin characters without deciding how international text should be handled.
- Leaving duplicate or trailing hyphens after replacement.
Related