Basic slug
Matches lowercase letters, digits and hyphens.
Suggested pattern
^[a-z0-9-]+$
What it matches
hello-worldproduct-123
Common limitations
- Allows leading and trailing hyphens.
- Does not prevent consecutive hyphens.
Visual regex workbench
Build, import, explain, test and share regex visually.
Regex guide
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.
Matches lowercase letters, digits and hyphens.
^[a-z0-9-]+$
hello-worldproduct-123Prevents leading and trailing hyphens.
^[a-z0-9]+(?:-[a-z0-9]+)*$
hello-worldbest-seo-guide-2026Allows underscores in addition to hyphens.
^[a-z0-9]+(?:[-_][a-z0-9]+)*$
hello_worldmy-post_2026Restricts slug length between 3 and 50 characters.
^(?=.{3,50}$)[a-z0-9]+(?:-[a-z0-9]+)*$
hello-worldshort-slugAllows international letters using Unicode properties.
^[\p{L}\p{N}]+(?:-[\p{L}\p{N}]+)*$
café-parisüber-unsbonjour-mondeA 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.
Clean and descriptive slugs make URLs easier to read for both users and search engines.
They often improve usability, sharing and search result visibility.
Most applications use lowercase letters, digits and hyphens.
Spaces are usually replaced with hyphens and special characters are removed or normalized.
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.
Modern websites sometimes allow Unicode characters directly inside URLs.
When supporting multiple languages, Unicode-aware slug validation may provide a better user experience.
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.