I've been yanking clumps of hair out for 30 minutes doing this one...
I have a dictionary, like so:
{'search': 'replace',
'foo': 'bar'}
And a string like this:
Foo bar %foo% % search %.
I'd like to replace each variable with it's equivalent text from the dictionary:
Foo bar bar replace.
My current regex fails, so here it is (key and value are from dictionary.items()):
re.sub(r'%\d+' + key + '[^%]\d+%', value, text)
Any help would be appreciated, as this regex stuff is driving me nuts...