I just did a quick test to confirm the behavior. I don't see it mentioned in the docs for pos, but I guess the reason would be that you're doing a substitution, so the matched text is essentially considered removed from the string at that point. Therefore pos will return the position where the substituted value will be inserted once you've computed it.