I can globally replace a regular expression with `re.sub()`, and I can count matches with

```
for match in re.finditer(): count++

```

Is there a way to combine these two, so that I can count my substitutions without making two passes through the source string?

Note: I'm not interested in whether the substitution matched, I'm interested in the exact count of matches in the same call, avoiding one call to count and one call to substitute.