Mega Code Archive

 
Categories / Python Tutorial / Regular Expressions
 

Re sub substitutes the leftmost, nonoverlapping occurrences of a pattern with a given replacement

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