Open this example in the interactive library
Source code
import re
print(re.sub(r'\d+', lambda m: str(int(m.group())*2), '3 apples and 4 pears'))Sample output
6 apples and 8 pears

Use a replacement callback. A self-contained example using the Python standard library.
Open this example in the interactive library
import re
print(re.sub(r'\d+', lambda m: str(int(m.group())*2), '3 apples and 4 pears'))6 apples and 8 pears