↧
Answer by Adam Smith for Python - Replace part of regex?
Two ways to do this, either capture your pre- and post-fixes, or use lookbehinds and lookaheads.# captures = "Example {String}"replaced = re.sub(r'({).*?(})', r'\1a\2', s)# lookarounds = "Example...
View ArticlePython - Replace part of regex?
I have the following piece of code:import res = "Example {String}"replaced = re.sub('{.*?}', 'a', s)print replacedWhich prints:Example aIs there a way to modify the regex so that it prints:Example...
View Article
More Pages to Explore .....