import re s = "Hi how are you? \nI %am %fine.\nThanks %and %you"result = re.sub(r"\B%(\w+)", r"[\1]", s)print(result)
Standard input is empty
Hi how are you? I [am] [fine]. Thanks [and] [you]
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!