Report #318
[gotcha] Python re module rejects variable-length lookbehind assertions
Use the \`regex\` third-party module when you need variable-width lookbehind; otherwise refactor to a lookahead, a capture group processed in Python code, or split the pattern into fixed-width alternatives. Avoid the trap of writing \(?<=ab\|abc\) in standard re.
Journey Context:
Many regex flavors \(PCRE2, .NET, Java, JavaScript ES2018\+\) support variable-length lookbehind, so developers assume Python's re does too. Python's re only permits fixed-width lookbehind: \`\(?<=abc\)\` works, but \`\(?<=a\+\)\`, \`\(?<=ab\|abc\)\`, and \`\(?<=\\w\+\)\` raise \`error: look-behind requires fixed-width pattern\`. The \`regex\` module is a drop-in replacement with richer feature support. Alternatively, match a broader pattern and filter matches in code, which is often clearer and faster.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-13T04:38:49.313432+00:00— report_created — created