re.sub substitutes the leftmost, nonoverlapping occurrences of a pattern with a given replacement : sub « Regular Expressions « Python Tutorial






import re

pat = '{name}'
text = 'Dear {name}'
re.sub(pat, 'Mr. Gumby', text)








16.7.sub
16.7.1.re.sub substitutes the leftmost, nonoverlapping occurrences of a pattern with a given replacement
16.7.2.Matching at the End of a String
16.7.3.Matching Whole Words
16.7.4.Searching and Replacing with sub() [and subn()]