Skip to main content

Lookahead and Lookbehind Assertions

Positive Lookbehind (?<=...)

0:00
LearnStep 1/3

Positive Lookbehind

Positive Lookbehind (?<=...)

Positive lookbehind asserts that the current position is immediately preceded by a match for the enclosed pattern. The syntax is (?<=...).

python

Fixed-Width Limitation

Important: In Python's standard re module, lookbehind patterns must have a fixed width.

  • Valid: (?<=abc), (?<=a|b)
  • Invalid: (?<=\w+), (?<=a*)