validation
Kebab-Case Slug Regex Pattern
Validates a URL-safe slug in kebab-case: lowercase letters and digits separated by single dashes. No leading or trailing dashes, no double dashes, no uppercase.
/^[a-z0-9]+(?:-[a-z0-9]+)*$/ What each part matches
^[a-z0-9]+ — start with one or more lowercase alphanumeric chars(?:-[a-z0-9]+)* — zero or more groups of (dash + more alphanumeric)$ — end✓ These match
- hello-world
- my-blog-post-2026
- utilko
- a1b2c3
✗ These don't
- Hello-World
- hello--world
- -hello
- hello-
- hello world
Use in your code
JavaScript
const re = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
re.test(input); // → true or false Python
import re
re.fullmatch(r"^[a-z0-9]+(?:-[a-z0-9]+)*$", input) PHP (PCRE)
preg_match('/^[a-z0-9]+(?:-[a-z0-9]+)*$/', $input); Go
re := regexp.MustCompile(`^[a-z0-9]+(?:-[a-z0-9]+)*$`)
re.MatchString(input) FAQ
Does this kebab-case slug regex work in JavaScript?
Yes. Every pattern in the Utilko regex library is tested to work in JavaScript RegExp, PCRE (PHP, Nginx), and Python `re`. Where flavor matters (lookbehind, named groups), the pattern page flags it.
How do I use this pattern?
Copy the pattern from the code block above. In JavaScript:
new RegExp('^[a-z0-9]+(?:-[a-z0-9]+)*$') or literal /^[a-z0-9]+(?:-[a-z0-9]+)*$/. Or click "Try in regex tester" to open it pre-loaded in Utilko's browser-based regex tester.Should I use this for security-critical validation?
Client-side regex is fine for UX (immediate feedback on a form). For anything security-critical — payments, auth, data integrity — always re-validate server-side using the same pattern PLUS domain-specific checks (Luhn checksum for cards, actual email delivery test, DNS resolution for domains).