If you have the following code:
import re
s1 = "aaa"
result = re.sub("a", "b", s1)
You can check if the call to sub made subsitutions by comparing the id of result to s1 like so:
id(s1) == id(result)
or, which is the same:
s1 is result
This is because strings in python are immutable, so if any substitutions are made, the result will be a different string than the original (ie: the original string is unchanged). The advantage of using the ids for comparison rather than the contents of the strings is that the comparison is constant time instead of linear.