JavaScript Regex Groups — exercises and bug fixes
5 hands-on exercises and 5 find-the-bug challenges for the JavaScript Regex Groups lesson. Every one is checked automatically in the browser — write the code, run it, and the tests tell you what still fails.
Exercises(5)
- 1
Capture the year
easy10 minPull the year out of the date with a group.
- 2
Use a named group
easy10 minName the group and read it from groups.
- 3
Repeat a group
easy10 minCheck the text is the pair ab repeated.
- 4
Match one of two words
easy10 minAccept only cat or dog.
- 5
Rearrange with groups
medium10 minTurn the ISO date into the British order.
Find the bug(5)
- 1
Fix the whole match used as a group
easy8 minPosition 0 is the full match; the groups start at 1.
- 2
Fix the replacement references
easy8 minThe parts are in the wrong order for a British date.
- 3
Fix the alternation without brackets
easy8 minWithout brackets the anchors apply to only one alternative.
- 4
Fix the quantifier on one character
easy8 minThe quantifier should repeat the whole pair, not just the b.
- 5
Fix the named group read by number
easy8 minA named group is read through groups, by its name.
Ready to write the code?
The editor, the automatic checks and the worked solutions open up with an account.
Open the workspace