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 Pattern | Name / Component | Function & Rule |
|---|---|---|
| ^[a-z0-9]+ | Initial Word | Must begin with alphanumeric chars. |
| (?:-[a-z0-9]+)*$ | Hyphenated Words | Repeats a single hyphen followed by more alphanumeric chars. |
Frequently Asked Questions
Can slugs contain underscores?
Related Regular Expressions
Browse All 40 PatternsNetwork & Web
HTTP & HTTPS URL Validation
Matches fully qualified URLs starting with http:// or https://, including subdomains, paths, ports, and query parameters.
/^https?:\/\/(?:www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}(?:\.[a-zA-Z0-9()]{1,6})?(?::[0-9]{1,5})?\b(?:[-a-zA-Z0-9()@:%_\+.~#?&\/=]*)$/iTest regex
Authentication & Security
Alphanumeric Username
Standard web application username policy: 3 to 20 characters, starting with a letter, allowing underscores.
/^[a-zA-Z][a-zA-Z0-9_]{2,19}$/Test regex
Code & Markup
Semantic Version (SemVer 2.0)
Full SemVer 2.0.0 specification regex validating major, minor, patch, and optional pre-release/build tags.
/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/Test regex