Pull the year out of the date with a group.
Acceptance criteria
- 1.#out should show 2026.
JavaScript Tutorial · JavaScript Regular Expressions
These 10 tasks go with the JavaScript Regex Groups chapter. 5 of them ask you to build something small from scratch; 5 give you code that is already broken and ask you to work out why. Set aside about 90 minutes for the whole set, though you can do them in any order.
Nothing here is marked by a person. When you press Submit, the editor checks your code against the points listed under each task and tells you straight away what passed and what didn't (you need a free account to submit). If you get stuck, there are hints, and a worked solution once you've had a go. The first 2 tasks are free; the rest are part of the practice plan.
If it's been a while since you read the chapter, here is how it starts: “Groups capture part of a match so you can use it afterwards.” .
1.Capture the yearexercise · easy · 10 min
Pull the year out of the date with a group.
Passes when: #out should show 2026.
2.Use a named groupexercise · easy · 10 min · practice plan
Name the group and read it from groups.
Passes when: #out should show 01.
3.Repeat a groupexercise · easy · 10 min · practice plan
Check the text is the pair ab repeated.
Passes when: #out should show a repeat.
4.Match one of two wordsexercise · easy · 10 min · practice plan
Accept only cat or dog.
Passes when: #out should show accepted.
5.Rearrange with groupsexercise · medium · 10 min · practice plan
Turn the ISO date into the British order.
Passes when: #out should show 15/01/2026.
6.Fix the whole match used as a groupbug fix · easy · 8 min
Position 0 is the full match; the groups start at 1.
Passes when: #out should show 4 characters.
7.Fix the replacement referencesbug fix · easy · 8 min · practice plan
The parts are in the wrong order for a British date.
Passes when: #out should show 15/01/2026.
8.Fix the alternation without bracketsbug fix · easy · 8 min · practice plan
Without brackets the anchors apply to only one alternative.
Passes when: #out should show rejected.
9.Fix the quantifier on one characterbug fix · easy · 8 min · practice plan
The quantifier should repeat the whole pair, not just the b.
Passes when: #out should show repeated pair.
10.Fix the named group read by numberbug fix · easy · 8 min · practice plan
A named group is read through groups, by its name.
Passes when: #out should show 01.
Between them these tasks cover Capture groups, Named groups and Alternation.
Looking for a different chapter? See every practice set, or switch to the interview theory questions.