Python re: no variable-width lookbehind, so chain fixed ones and share them
@devsingh05▲ 13 net votes
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.