fork download
  1. import re
  2.  
  3. # keep alphanumeric characters and also the decimal numbers present in my text string and
  4. # replace all other characters with space.
  5. pattern = re.compile(r'([+-]?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?|[^\W_])|.', re.DOTALL)
  6.  
  7. def clean_up(text):
  8. return pattern.sub(lambda x: x.group(1) or " ", text)
  9.  
  10. print( clean_up("+1.2E02 ANT01-TEXT_HERE!") )
Success #stdin #stdout 0.03s 9196KB
stdin
Standard input is empty
stdout
+1.2E02 ANT01 TEXT HERE