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

Validation Result: MATCH ✓

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

JavaScript
const slugRegex = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
const isValid = slugRegex.test(slug);
Python
import re
pattern = r"^[a-z0-9]+(?:-[a-z0-9]+)*$"
is_valid = bool(re.match(pattern, slug))
Go (Golang)
matched, err := regexp.MatchString(`^[a-z0-9]+(?:-[a-z0-9]+)*$`, slug)
PHP
$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.

🔗 Share this page

TelegramWhatsAppX