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.

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

Tested live on the JavaScript engine. Other flavors are validated and flagged for differences, not executed.

No samples.

Related regex recipes