Practice

Regex Exercises: A Practice Path from Beginner to Advanced

A good Regex exercise includes a clear goal plus positive and negative examples. That lets you measure whether your pattern really expresses the intended rule.

Before you start: test every pattern with examples that should match and examples that should fail.

Level 1: literals and wildcards

Match cat in different positions, then match cat, cot, and cut with one pattern. Explain why c.t works before moving on.

Level 2: character classes and quantifiers

Build patterns for two uppercase letters followed by two digits, repeated a characters, and words with an optional letter.

Level 3: anchors and validation

Require the whole string to match. Compare [A-Z]{2}\d{2} with ^[A-Z]{2}\d{2}$ using values that contain the pattern in the middle.

Level 4: real-world formats

Try dates, phones, simple emails, URLs, and log lines. For every task, invent at least three negative cases.

Level 5: refactor and explain

Once a pattern works, make it readable and explain every token. The shortest Regex is not always the most maintainable Regex.

Next step: test it for real

Use the Playground to experiment with the pattern, then practice in the game with feedback on false positives and false negatives.

Practice in the gameTest in Playground

Keep learning

← Back to learning hub