On , I learnt ...

How to use look-behind regex assertions with ripgrep

By default ripgrep uses Rust’s [regex] crate for parsing regular expressions which does not support look-ahead or look-behind assertions.

To use such zero width assertions, use the --pcre2 option:

rg --pcre2 'A(?=B)'   # look ahead positive
rg --pcre2 'A(?!B)'   # look ahead negative
rg --pcre2 'A(?<=B)'  # look behind positive
rg --pcre2 'A(?<!B)'  # look behind negative