Before this lesson
Understand regex literals, test, whole-input validation and JavaScript string escaping.
What you will be able to do
Understand single-character classes and express allowed characters precisely.
Understand the mechanism
A class chooses one character: [abc] does not match the entire string abc. [a-z] covers ASCII lowercase letters; [^0-9] matches one non-ASCII-digit character. Place a literal hyphen last to avoid a range.
JavaScript \d matches 0 through 9. \w primarily describes ASCII letters, digits and underscore, not all writing systems. \s includes line breaks; use [ \t] when only spaces and tabs are allowed.
The username starts with a lowercase letter, then permits lowercase letters, digits, underscore or hyphen, totaling 3 to 12 characters. \b marks a word/nonword boundary, not general natural-language segmentation.
Runnable example
const username = /^[a-z][a-z0-9_-]{2,11}$/;
console.log(JSON.stringify(["ada_7", "7ada", "ab", "a-b", "学习者"].map(s => username.test(s))));
console.log(JSON.stringify("one\t two\nthree".split(/[ \t]+/)));
console.log(JSON.stringify("cat scatter cat_2 cat!".match(/\bcat\b/g)));
Trace and verify
Username results are true, false, false, true, false. Splitting only spaces and tabs leaves the newline inside the last segment. Word matching finds the first and last cat.
Common mistakes and boundaries
Do not substitute [A-z] for [A-Za-z], because the intervening code points include punctuation. A whitelist is a business constraint, not a judgment that other names or scripts are invalid.
Practice challenge
Allow an uppercase initial while leaving subsequent characters unchanged.
Reference solution and reasoning
Change only the initial class to [A-Za-z], without an i flag. Ada passes but aDa does not, because only the first position was relaxed.