JavaScript Regular Expressions — exercises and bug fixes
5 hands-on exercises and 5 find-the-bug challenges for the JavaScript Regular Expressions 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
Test for a word
easy10 minReport whether the text contains cat.
- 2
Ignore the case
easy10 minUse a flag so a capital C still matches.
- 3
Find every match
easy10 minCount how many times cat appears.
- 4
Replace every match
easy10 minChange all the cats to dogs.
- 5
Build a pattern from a variable
medium10 minCreate the pattern with RegExp and test it.
Find the bug(5)
- 1
Fix the pattern written in quotes
easy8 minA pattern goes between slashes, not quotes.
- 2
Fix the missing i flag
easy8 minThe capital letter stops the pattern matching.
- 3
Fix the missing g flag
easy8 minWithout g only the first match is found.
- 4
Fix only the first replaced
easy8 minEvery cat should become a dog.
- 5
Fix the unguarded match
easy8 minA failed match gives null, which has no length.
Ready to write the code?
The editor, the automatic checks and the worked solutions open up with an account.
Open the workspace