Skip to main content

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. 1

    Anchor both ends

    easy10 min

    Reject a value that merely contains four digits.

  2. 2

    Anchor the start

    easy10 min

    Check the address begins with https.

  3. 3

    Anchor the end

    easy10 min

    Check the file name ends with pdf.

  4. 4

    Use a word boundary

    easy10 min

    Check cat does not match inside concatenate.

  5. 5

    Count whole words

    medium10 min

    Count only the standalone occurrences of cat.

Find the bug(5)

  1. 1

    Fix the unanchored validation

    easy8 min

    Without anchors any text containing four digits passes.

  2. 2

    Fix the extension checked at the start

    easy8 min

    The extension is at the end of the name.

  3. 3

    Fix the missing end anchor

    easy8 min

    Without the end anchor a disguised file passes.

  4. 4

    Fix the missing word boundaries

    easy8 min

    Without boundaries the word matches inside a longer one.

  5. 5

    Fix the caret used inside brackets

    easy8 min

    Inside 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