fork download
  1. import re
  2.  
  3. regex = r"(?<=[a-zA-Z])(\d)(?!\d)"
  4. test_str = ("Z9_M50_P3_2X_MY_STRING")
  5. subst = "0\\1"
  6. result = re.sub(regex, subst, test_str, 0, re.MULTILINE)
  7.  
  8. if result:
  9. print (result)
  10.  
  11.  
Success #stdin #stdout 0.02s 6828KB
stdin
Standard input is empty
stdout
Z09_M50_P03_2X_MY_STRING