JavaScript Regex Quantifiers — exercises and bug fixes
5 hands-on exercises and 5 find-the-bug challenges for the JavaScript Regex Quantifiers 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
Match one or more digits
easy10 minPull the whole number out of the text.
- 2
Group runs of characters
easy10 minFind every run of digits and join them.
- 3
Make a letter optional
easy10 minMatch both spellings of the colour word.
- 4
Require an exact count
easy10 minCheck the value is exactly four digits.
- 5
Match lazily
medium10 minUse a lazy quantifier to stop at the first closing bracket.
Find the bug(5)
- 1
Fix the missing quantifier
easy8 minWithout a plus only one digit is matched.
- 2
Fix the greedy match
easy8 minA greedy quantifier swallows both tags instead of stopping at the first.
- 3
Fix the star used where plus is needed
easy8 minA star allows zero characters, so empty text passes.
- 4
Fix the wrong exact count
easy8 minA year needs four digits, not three.
- 5
Fix the optional marker on the wrong character
easy8 minThe u is the optional letter, not the r.
Ready to write the code?
The editor, the automatic checks and the worked solutions open up with an account.
Open the workspace