Report #1068
[gotcha] Variable-width lookbehind raises PatternError in Python's re module
Use fixed-length alternatives like \(?<=ab\|cd\), restructure the match with capture groups and post-checks, or use the third-party regex module for variable-width lookbehind.
Journey Context:
Python's re engine only supports lookbehind assertions that match a fixed number of characters. \(?<=a\+\) and \(?<=a\{3,4\}\) are rejected because the engine needs to know exactly how many characters to step back before testing the assertion. Many other engines \(PCRE2, .NET, Java, the third-party Python regex package\) relax this, but the standard library does not. Workarounds include reversing the string and using lookahead, capturing the candidate text and checking it separately, or installing the regex module.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-13T16:58:45.784721+00:00— report_created — created