Web
URL Slug
Validate URL slugs: lowercase letters and digits separated by single hyphens, no leading/trailing hyphens.
Try it in RegexPro →Available in
Pattern
regexengine-agnostic
^[a-z0-9]+(?:-[a-z0-9]+)*$Raw source: ^[a-z0-9]+(?:-[a-z0-9]+)*$
How it works
Anchored with ^ and $. Requires at least one alphanumeric character. Hyphens can only appear between alphanumeric groups — not at start or end.
Examples
Input
my-blog-postMatches
my-blog-post
Input
hello-world-123Matches
hello-world-123
Input
-bad-slug-No match
—Common use cases
- •CMS URL slug validation
- •SEO-friendly URL generation
- •Blog post/product permalink checks
- •Route parameter sanitisation
Related patterns
Slug (Unicode Letters Allowed)
WebValidate URL slugs allowing Unicode letters (`café-rénové`), as supported by Next.js i18n routing.
HTML5 Color Input Value
WebValidate the value of an HTML5 `<input type="color">` — exactly 6 hex digits with leading hash.
URL Path Segment
WebMatch individual `/segment` parts of a URL path, capturing each one.
URL Query String
WebExtract the query string portion of a URL (everything between `?` and `#` or end-of-string).