Regex for URL slug matching in JavaScript

A URL slug is lowercase letters, digits, and hyphens. This anchored pattern validates a whole slug string. Tune it with the live tester below.

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

Try it live

The pattern and sample strings below are pre-loaded. Edit anything, or describe a variation in plain English and generate your own.

Save your patterns across devices.
/^[a-z0-9]+(?:-[a-z0-9]+)*$/valid ✓

One sample per line. Tested live on the JavaScript engine — other flavors are validated and flagged for differences, not executed.

No samples.

Related regex recipes