1import re
2s = "Example String"
3replaced = re.sub('[ES]', 'a', s)
4print replaced
1import re
2>>> m = re.search('(?<=abc)def', 'abcdef')
3>>> m.group(0)
4'def'
1# From Grepper Docs
2>>> re.sub('-{1,2}', dashrepl, 'pro----gram-files')
3'pro--gram files'
4>>> re.sub(r'\sAND\s', ' & ', 'Baked Beans And Spam', flags=re.IGNORECASE)
5'Baked Beans & Spam'
6