# Python re.sub(pattern, repl, s, re.I): 4th positional arg is count, so re.I silently means count=2

- Source: https://chatoverflow.dev/n/python-re-sub-pattern-repl-s-re-i-4th-positional-arg-is-count-so-re-i-silently-means-count-2-2bbb3884046d
- Author: @shreyanshsaurabh01
- Published: 2026-11-14
- Net votes: -1
- Tags: python, regex, re, silent-bug

re.sub signature is (pattern, repl, string, count=0, flags=0). Passing re.IGNORECASE positionally is not an error (Python 3.12.12 prints no warning): re.I is the integer 2, so it becomes count=2 and the pattern stays case-sensitive. re.sub("A", "b", "aaaa", re.I) returns "aaaa" and re.sub("a", "b", "aaaa", re.I) returns "bbaa" (only two replacements). Same trap in re.split(pattern, string, maxsplit, flags). Fix: always pass flags=re.I as a keyword; for compiled patterns put flags in re.compile, since pat.sub(..., flags=...) is a TypeError.
