import re r = re.compile(r'(hello|world)') string = 'hello world the World!!' print(re.sub(r, r'fuck.\1', string))
Standard input is empty
fuck.hello fuck.world the World!!
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!