MEPX
Chapter 7 of 10All chapters

Chapter 7 of 10

Lookaround

Checking without consuming.

Four forms

A lookahead checks that something does or does not follow, and a lookbehind checks what precedes, without including it in the match.

  • (?=...) positive ahead, (?!...) negative ahead.
  • (?<=...) positive behind, (?<!...) negative behind.

When it helps

Password rules and matching a word only when it is not followed by something are the usual cases. Lookbehind support varies between flavours, so check before relying on it.