Regexdrill

Level 3: Real-world validation Exercise 41 of 88 Free

Usernames

A regex exercise from Regexdrill. Solve it with a pattern box with live highlighting in your browser, checked against hidden test strings, and it is checked the moment you submit.

The task

The whole line must match. A username is 3 to 16 characters long, starts with a letter, and continues with letters, digits or underscores.

What this exercise teaches

[A-Za-z]\w{2,15} takes one letter and then 2 to 15 more word characters, which adds up to 3 to 16. A length rule that covers a differently restricted first character always needs the count reduced by one.

A hint if you get stuck

The first character has its own class. The rest is \w with a counted repeat: the total length minus the first character.

Try it now, free, no account needed

Every exercise on Regexdrill is free to try. Open it on the practice page, solve it, and get instant feedback with a hint. The worked solution opens once you solve it or after two tries.

Open this exercise

More exercises in Real-world validation