gettoolz.app

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.

Pattern^[a-z0-9]+(?:-[a-z0-9]+)*$
JavaScript literal/^[a-z0-9]+(?:-[a-z0-9]+)*$/

What 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.

Inputs tested against the URL slug regex
InputResultWhy
hello-worldPassestwo words
regex-testerPassesthe slug of this tool
2026-roadmapPassesdigits count as a word
aPassesa single character
Hello-WorldFailsupper case
hello--worldFailsa double hyphen
-helloFailsa leading hyphen
hello_worldFailsan underscore
caféFailsa 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

Or open the regex tester empty and bring your own pattern.