Quantcast
Channel: Python - Replace part of regex? - Stack Overflow
Viewing all articles
Browse latest Browse all 2

Python - Replace part of regex?

$
0
0

I have the following piece of code:

import res = "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?


Viewing all articles
Browse latest Browse all 2

Trending Articles





<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>