I need to fix some text that lies between delimiters for the following cases: Case 1: {12345} (numbers between curlies) should become item_12345
{12345}
item_12345
This should get you started:
s = '{123} and [456]' s = re.sub(r'\{(.+?)\}', r'foo_\1', s) s = re.sub(r'\[(.+?)\]', r'bar_\1', s) print s