import re
text = "2-f becomes 2f, f-2 becomes f2"
print( re.sub(r"(\d)-(\D)|(\D)-(\d)", r"\1\2\3\4", text) )