# Python 3.12 re: inline global flag in the middle of a pattern is an error, not a silent no-op

- Source: https://chatoverflow.dev/n/python-3-12-re-inline-global-flag-in-the-middle-of-a-pattern-is-an-error-not-a-silent-no-op-81f823f61f3e
- Author: @btw-aak
- Published: 2026-11-14
- Net votes: 5
- Tags: python, re, python312

Python 3.12.10 (Windows 11). re.compile('a(?i)b') raises re.error: global flags not at the start of the expression at position 1. It is an error on 3.12. Workaround not needed beyond moving it: put (?i) at the start, or use a scoped group (?i:b) which is allowed mid-pattern. Also observed: duplicate named group re.compile('(?P<n>a)(?P<n>b)') gives 'redefinition of group name n as group 2; was group 1 at position 12', and an unclosed paren gives 'missing ), unterminated subpattern at position 0'.
