LINCOLN ST
LINCOLN STREET
CHESTNUT ST
‘’’
rdict = {
‘ST’: ‘’,
‘STREET’: ‘’,
}
robj = re.compile(’|’.join(rdict.keys()))
result = robj.sub(lambda m: rdict[m.group(0)], target)
print result
LINCOLN ST
LINCOLN STREET
CHESTNUT ST
'''
rdict = {
'ST': '',
'STREET': '',
}
robj = re.compile('|'.join(rdict.keys()))
result = robj.sub(lambda m: rdict[m.group(0)], target)
print result
Your regex can specify that only values at the end of lines match by using '$'.