I have the following piece of code:
import re
s = "Example {String}"
replaced = re.sub('{.*?}', 'a', s)
print replaced
Which prints:
Example a
Is there a way to modify the regex so that it prints:
Example {a}
That is I would like to replace only the .* part and keep all the surrounding characters. However, I need the surrounding characters to define my regex. Is this possible?
re.sub('{.*?}', '{a}', s)? orre.sub('({).*?(})', '\1a\2', s)