fork download
  1. import re
  2. text = "2-f becomes 2f, f-2 becomes f2"
  3. print( re.sub(r"(\d)-(\D)|(\D)-(\d)", r"\1\2\3\4", text) )
Success #stdin #stdout 0.03s 9616KB
stdin
Standard input is empty
stdout
2f becomes 2f, f2 becomes f2