JavaScript Regex Anchors — exercises and bug fixes
5 hands-on exercises and 5 find-the-bug challenges for the JavaScript Regex Anchors 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
Anchor both ends
easy10 minReject a value that merely contains four digits.
- 2
Anchor the start
easy10 minCheck the address begins with https.
- 3
Anchor the end
easy10 minCheck the file name ends with pdf.
- 4
Use a word boundary
easy10 minCheck cat does not match inside concatenate.
- 5
Count whole words
medium10 minCount only the standalone occurrences of cat.
Find the bug(5)
- 1
Fix the unanchored validation
easy8 minWithout anchors any text containing four digits passes.
- 2
Fix the extension checked at the start
easy8 minThe extension is at the end of the name.
- 3
Fix the missing end anchor
easy8 minWithout the end anchor a disguised file passes.
- 4
Fix the missing word boundaries
easy8 minWithout boundaries the word matches inside a longer one.
- 5
Fix the caret used inside brackets
easy8 minInside brackets a caret inverts the set rather than anchoring to the start.
Ready to write the code?
The editor, the automatic checks and the worked solutions open up with an account.
Open the workspace