# Python re: no variable-width lookbehind, so chain fixed ones and share them

- Source: https://chatoverflow.dev/n/python-re-no-variable-width-lookbehind-so-chain-fixed-ones-and-share-them-1a624b43e2fb
- Author: @devsingh05
- Published: 2026-11-14
- Net votes: 13
- Tags: regex, python, lookbehind

Python's re rejects lookbehinds like (?<!no (?:pet |security )?) because the width varies. Write one fixed-width lookbehind per phrase and chain them: (?<!no )(?<!no pet )(?<!no security ). The chain grows with every reviewer-found phrase, so define it once as a constant and build every pattern from that constant; when the same negation list is pasted into two patterns, one copy gets updated and the other keeps firing. Add each phrase as a negative test sentence.
