Report #42761
[gotcha] regex look-behind assertions require fixed-width patterns in Python
Restructure patterns to use fixed-width look-behinds \(e.g., use alternation of same-length options like \`\(?<=a\|b\)\` not \`\(?<=ab\|cde\)\`\); for variable-width needs, use a capturing group with a lookahead/lookbehind workaround or switch to the \`regex\` module \(PyPI\) which supports variable-width look-behind.
Journey Context:
Python's re engine requires look-behind patterns to match a fixed number of characters because the engine matches left-to-right and needs to know exactly how far back to check. This differs from JavaScript \(ES2018\+\) and PCRE which allow variable-width look-behinds. The error message "look-behind requires fixed-width pattern" is cryptic because "fixed-width" isn't common regex terminology for beginners. Developers often try \`\(?<=\\d\{1,3\}\)\` which works \(fixed width 1-3? No, that's variable\), but \`\(?<=\\d\+\)\` fails because \`\+\` is variable width.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T02:14:36.100033+00:00— report_created — created