Skip to main content
Module 6 · Lesson 1 of 421/32 in the course~16 min
Module lessons (1/4)

Positive lookahead: `(?=...)`

Lesson preview5 hands-on exercises readyRegex Course · Module 6 — Lookaround

Check that a certain pattern follows the current position, without consuming it.

What you'll learn in this lesson

  • Write lookahead positive assertions (?=...) to test what follows a position without consuming it.
  • Understand the concept of zero-width: the match stops before the requested context and the cursor starts from there.
  • Combine multiple lookaheads anchored to ^ to validate independent rules (e.g. password strength).

Overview

A positive lookahead (?=...) is a zero-width assertion: it checks for a certain pattern immediately after the current position, but doesn't consume those characters in the final match.

Imagine the lookahead as a visual check around the corner: the engine peers forward to check a condition ("is there really euro after these digits?"). If the check succeeds, the engine returns to the original position before the corner and returns only what it had matched up to that point.

Sections covered in this lesson

  1. 1Mental model: the guard at the gate without moving forward
  2. 24 progressive examples step by step
  3. 3Guided practical exercises
  4. 4Quick check
Pro Lesson · Module 6 — Lookaround

Unlock "Positive lookahead: `(?=...)`" and the full Regex Course curriculum

Check that a certain pattern follows the current position, without consuming it.

Unlock all 5 hands-on exercises in this lesson plus every advanced WebAssembly module with automated checks.

  • Instant access to all advanced modules in Regex Course plus 17 more courses
  • Hands-on browser exercises with automated test suites and solutions
  • 14-day money-back guarantee processed via Paddle.com

14-day guarantee · Cancel anytimeModule 1, all 18 interactive games, and cheatsheets are always free.