Skip to main content
Regexflux

URL Slug

beginner

Matches URL-safe slug strings like 'my-blog-post-title'.

urlslugseovalidation

Pattern

/^[a-z0-9]+(?:-[a-z0-9]+)*$/

Try It

0 of 8 strings matched

Explanation

Matches lowercase alphanumeric strings with hyphens as word separators. No leading/trailing hyphens, no consecutive hyphens. Common format for SEO-friendly URLs.

Test Strings

Matching

  • my-blog-post
  • hello-world-123
  • single

Non-matching

  • -leading
  • trailing-
  • UPPERCASE
  • has spaces
  • double--hyphen

Language Compatibility

LanguageSupport
JSFull support
PYTHONFull support
JAVAFull support
PHPFull support
GOFull support

Code Snippets

const regex = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
const text = "your text here";
const matches = text.match(regex);
console.log(matches);

Common Variations

With underscores

^[a-z0-9]+(?:[-_][a-z0-9]+)*$

Also allows underscores as separators

Related Patterns