import remystring = '2 apple trees yield 4 apples'by = 2print(re.sub(r'\d+', lambda x: str(int(x.group())*by), mystring))
Standard input is empty
4 apple trees yield 8 apples
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!