//g
  • 100% Free
  • No Sign-Up
  • No Credit Card
  • No Free Trial
  • No Pro Tier
  • No Watermarks

Nothing is uploaded. Just open it and start.

URL Slug Regex

Lowercase letters and digits in words joined by single hyphens, as used in web addresses.

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

Piece by piece

  1. ^the start of the text
  2. [a-z0-9]+one of a–z, 0–9, repeated 1 or more times, as many as possible
  3. (?:a group (not captured)
  4. -the character “-”
  5. [a-z0-9]+one of a–z, 0–9, repeated 1 or more times, as many as possible
  6. )*end of the group, repeated 0 or more times, as many as possible
  7. $the end of the text

Examples

TextResult
hello-worldMatches
regex-testerMatches
post-2026Matches
Hello-WorldDoesn't match
-leadingDoesn't match
double--hyphenDoesn't match
trailing-Doesn't match
  • Only plain ASCII: accented letters need to be turned into plain ones first.

Other common patterns

Test any regular expression →

Frequently asked questions

How do I use this url slug regex in JavaScript?
Write it as /^[a-z0-9]+(?:-[a-z0-9]+)*$/ and call re.test(text). It is anchored with ^ and $, so it checks the whole text; remove them to find it inside longer text (and add the g flag to find every one). The Code view writes it out for Python, Go and PHP too.
Is it a complete validator?
No regex is the whole story. Only plain ASCII: accented letters need to be turned into plain ones first.
Can I try it on my own text?
Yes. The tester above already holds the examples; paste your own text over them and every match is highlighted as you type. Nothing is uploaded.

Spotted a bug or have a suggestion?

Found something broken, have an idea, or just want to say thanks about any of our tools? Every message reaches a real person.