Marc
Marc

Reputation: 412

Regular expression for folders

I want a regular expression to test a string that meets the following requirements:

It should match the following strings:

Could someone please help me with it? Thanks in advance!

Upvotes: 0

Views: 1048

Answers (1)

Niet the Dark Absol
Niet the Dark Absol

Reputation: 324800

You have your pieces, so put them together:

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

This does exactly what you're looking for. The only complicated part is allowing a single character.

Upvotes: 3

Related Questions