Regex for URL Slug (kebab-case)
Canonical regex for SEO-friendly kebab-case URL slugs: matches lowercase alphanumeric tokens cleanly joined by single hyphens.
⚡ Live Interactive Sandbox
Pattern Breakdown & Tokens
- • ^[a-z0-9]+ — slug must begin with alphanumeric character
- • (?:-[a-z0-9]+)*$ — zero or more subsequent groups joined by single hyphen
Code Snippets
const slugRegex = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
const isValid = slugRegex.test(slug); import re
pattern = r"^[a-z0-9]+(?:-[a-z0-9]+)*$"
is_valid = bool(re.match(pattern, slug)) matched, err := regexp.MatchString(`^[a-z0-9]+(?:-[a-z0-9]+)*$`, slug) $isValid = preg_match('/^[a-z0-9]+(?:-[a-z0-9]+)*$/', $slug); Open the full tool: Open Full Regex Tester →
FAQ
How does this regular expression for URL Slug (kebab-case) work?
Canonical regex for SEO-friendly kebab-case URL slugs: matches lowercase alphanumeric tokens cleanly joined by single hyphens. The pattern is: ^[a-z0-9]+(?:-[a-z0-9]+)*$
How to use this regex in JavaScript and Python?
In JavaScript: new RegExp("^[a-z0-9]+(?:-[a-z0-9]+)*$").test(input). In Python: re.match(r"^[a-z0-9]+(?:-[a-z0-9]+)*$", input).
Can I test complex regular expressions online?
Yes, use our full in-browser Regex Tester tool with live syntax highlighting, group capture table, and zero server uploads.