Visual regex workbench

Build, import, explain, test and share regex visually.

Regex guide

Slug Regex Examples

Slug validation is useful for blog posts, CMS platforms, product pages and SEO-friendly URLs. This guide provides practical slug regex patterns for common web applications.

Basic slug

Matches lowercase letters, digits and hyphens.

Suggested pattern

^[a-z0-9-]+$
Quick test

What it matches

  • hello-world
  • product-123

Common limitations

  • Allows leading and trailing hyphens.
  • Does not prevent consecutive hyphens.

SEO-friendly slug

Prevents leading and trailing hyphens.

Suggested pattern

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

What it matches

  • hello-world
  • best-seo-guide-2026

Common limitations

  • Lowercase ASCII characters only.
  • Does not support accented characters.

Slug with underscores

Allows underscores in addition to hyphens.

Suggested pattern

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

What it matches

  • hello_world
  • my-post_2026

Common limitations

  • Only lowercase ASCII characters.
  • Does not allow spaces.

Fixed-length slug

Restricts slug length between 3 and 50 characters.

Suggested pattern

^(?=.{3,50}$)[a-z0-9]+(?:-[a-z0-9]+)*$
Quick test

What it matches

  • hello-world
  • short-slug

Common limitations

  • Length rules may vary by application.
  • Lowercase ASCII only.

Unicode slug

Allows international letters using Unicode properties.

Suggested pattern

^[\p{L}\p{N}]+(?:-[\p{L}\p{N}]+)*$
Quick test

What it matches

  • café-paris
  • über-uns
  • bonjour-monde

Common limitations

  • Requires Unicode regex support.
  • Behavior may vary between regex engines.

What is a slug?

A slug is the human-readable part of a URL used to identify a page, article, product or resource.

Examples include hello-world, best-seo-guide and product-123.

Why are slugs important for SEO?

Clean and descriptive slugs make URLs easier to read for both users and search engines.

They often improve usability, sharing and search result visibility.

Common slug rules

Most applications use lowercase letters, digits and hyphens.

Spaces are usually replaced with hyphens and special characters are removed or normalized.

Slug validation vs slug generation

Regex is useful for validating an existing slug, but generating a slug usually requires additional processing.

Typical slug generation includes lowercasing text, removing accents and replacing spaces with hyphens.

Unicode slugs and international websites

Modern websites sometimes allow Unicode characters directly inside URLs.

When supporting multiple languages, Unicode-aware slug validation may provide a better user experience.

When to use a slug regex

Slug regex patterns are useful in CMS platforms, blogs, e-commerce websites, APIs and content management tools.

They help ensure consistent and URL-safe identifiers across an application.