URL slug regex
Lower-case letters and digits in words joined by single hyphens, with no hyphen at either end. Copy the pattern, with 4 inputs it accepts and 5 it rejects, each checked against it at build time.
Part of developer tools.
^[a-z0-9]+(?:-[a-z0-9]+)*$/^[a-z0-9]+(?:-[a-z0-9]+)*$/Flags: none
Open in the testerWhat the url slug regex accepts and rejects
Each result below is the output of the pattern itself, run on the input when this page was built — not a claim copied next to it. A wrong verdict stops the build.
| Input | Result | Why |
|---|---|---|
| hello-world | Passes | two words |
| regex-tester | Passes | the slug of this tool |
| 2026-roadmap | Passes | digits count as a word |
| a | Passes | a single character |
| Hello-World | Fails | upper case |
| hello--world | Fails | a double hyphen |
| -hello | Fails | a leading hyphen |
| hello_world | Fails | an underscore |
| café | Fails | a non-ASCII letter |
Limits
- Accented and non-Latin letters are refused, so a title has to be transliterated (café → cafe) before it becomes a slug. Browsers can display Unicode paths, but they get percent-encoded as soon as they are copied.
- Length is not limited; add {1,80} style bounds, or check the length separately, if your URLs have a budget.
Try it on your own input
Open this pattern in the regex tester with every example above on its own line. The link adds the g and m flags so that ^ and $ hold per line and every line is tested: the highlighted lines are the ones marked as passing here. Paste your own data in place of the examples — it is matched in your browser and never uploaded.
Other common regexes
- Email address
- URL
- UUID
- IPv4 address
- Hex color
- ISO 8601 date
- 24-hour time
- Semantic version
- Phone number (E.164)
- US ZIP code
- MAC address
Or open the regex tester empty and bring your own pattern.