Regex Lookaround

Assert context without consuming: lookahead and lookbehind.

  • lookahead
  • lookbehind
  • password regex
  • zero-width
  • regex assert

Regex Lookaround

Assert context without consuming: lookahead and lookbehind.

Commands

CommandWhat it does
foo(?=bar)foo followed by bar
foo(?!bar)foo NOT followed by bar
(?<=@)\w+Word after at-sign
^(?=.*[A-Z])(?=.*\d).{8,}$Password rule via lookaheads

Example

^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[A-Za-z\d@$!%*?&]{8,}$

FAQ

Why is my lookbehind rejected in JavaScript?

Older engines allow only lookahead; modern V8 supports fixed-length lookbehind - keep it fixed-width.

Lookaround vs consuming patterns?

Lookaround asserts context and keeps the cursor in place, so overlapping conditions stay checkable.

الأسئلة الشائعة

Why is my lookbehind rejected in JavaScript?
Older engines allow only lookahead; modern V8 supports fixed-length lookbehind - keep it fixed-width.
Lookaround vs consuming patterns?
Lookaround asserts context and keeps the cursor in place, so overlapping conditions stay checkable.

Regex