fork download
  1. import re
  2.  
  3. exceptions = [
  4. re.escape("log"),
  5. re.escape("sin"),
  6. re.escape("cos"),
  7. r"[+-]?\d*\.?\d+(?:e[+-]?\d+)?"
  8. ]
  9.  
  10. s = "(var1 * 1.3e4 + abc)/log(blabla+2E3)*1.2E+23"
  11. r = r"\b(?!(?:" + "|".join(exceptions) + r")\b)\w+\b"
  12.  
  13. print re.sub(r, "1", s, 0, re.I)
Success #stdin #stdout 0.02s 6924KB
stdin
Standard input is empty
stdout
(1 * 1.3e4 + 1)/log(1+2E3)*1.2E+23