Regular Expressions Lookahead and Lookbehind

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!

Syntax

  • Positive lookahead: (?=pattern)
  • Negative lookahead: (?!pattern)
  • Positive lookbehind: (?<=pattern)
  • Negative lookbehind: (?<!pattern)

Remarks

Not supported by all regex engines.

Additionally, many regex engines limit the patterns inside lookbehinds to fixed-length strings. For example the pattern (?<=a+)b should match the b in aaab but throws an error in Python.

Capturing groups are allowed and work as expected, including backreferences. The lookahead/lookbehind itself is not a capturing group, however.



Got any Regular Expressions Question?