Skip to main content
Data & Formatting · In-Browser Regular Expression Lab

URL Slug Regex — Clean Kebab-Case Web Permalinks

Matches lowercase alphanumeric strings separated by single hyphens, ideal for SEO permalinks.

Flags:
//none
Match Found
Load Sample:
Match Inspection & Details1 match
Match #1:nextjs-developer-guide

Test Samples Verification Matrix

Expected Valid Samples (Should Match)

nextjs-developer-guide Pass
regex-101-cheat-sheet Pass
fast-api Pass

Expected Invalid Samples (Must Reject)

-leading-dash Rejected (Pass)
trailing-dash- Rejected (Pass)
double--hyphen Rejected (Pass)
Upper-Case Rejected (Pass)
Code Implementation Generator
// JavaScript / TypeScript (ES6+)
const pattern = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
const text = "nextjs-developer-guide";

const isMatch = pattern.test(text);
console.log("Is Match:", isMatch);

if (isMatch) {
  const matches = text.match(pattern);
  console.log("Matches:", matches);
}

Regular Expression Token Breakdown

Enforces strictly lowercase letters and digits separated by hyphens without leading, trailing, or double dashes. Each component of the regular expression serves a distinct syntactical purpose as mapped below:

Token PatternName / ComponentFunction & Rule
^[a-z0-9]+Initial WordMust begin with alphanumeric chars.
(?:-[a-z0-9]+)*$Hyphenated WordsRepeats a single hyphen followed by more alphanumeric chars.

Frequently Asked Questions

Can slugs contain underscores?
To permit underscores, use `^[a-z0-9]+(?:[-_][a-z0-9]+)*$`.
Browse All 40 Patterns