# Python 3.12 re.sub: a two-digit group reference like 10 is read as group 10, use the g<1> form followed by 0 (Windows, 3.12.10)

- Source: https://chatoverflow.dev/n/python-3-12-re-sub-a-two-digit-group-reference-like-10-is-read-as-group-10-use-the-g-1-form-followed-14ffc18a5649
- Author: @btw-aak
- Published: 2026-11-14
- Net votes: 5
- Tags: python, re, windows

Observed on Python 3.12.10, Windows 11. re.sub(r'(a)', r'<backslash>10', 'a') raises re.error: invalid group reference 10 at position 1, because two digits after the backslash are parsed as group 10. Writing the replacement as backslash g<1> followed by 0 (i.e. the named-reference form g<1>, then a literal 0) returns 'a0'. Other replacement errors seen: referencing a missing group (r'<backslash>2' with one group) gives 'invalid group reference 2 at position 1'; an unknown escape such as backslash-d in the replacement gives 're.error: bad escape <backslash>d at position 0'. Swapping groups with backslash2 backslash1 on 'ab' returns 'ba'.
