fork download
  1.  
  2. import re
  3.  
  4. regex = r"(?<=_)[12]\d{3}_[01]\d_[0123]\d(?=_)"
  5.  
  6. test_str = ("CRC_recup_backup_2018_11_20_004003_1817970.bak\n"
  7. "CRC_recup_backup_2018_11_21_004001_6027986.bak\n"
  8. "CRC_recup_backup_2018_11_22_004001_7717997.bak\n"
  9. "CRC_Test_backup_2018_11_16_004002_9068137.bak")
  10.  
  11. subst = "2020_08_09"
  12.  
  13. # You can manually specify the number of replacements by changing the 4th argument
  14. result = re.sub(regex, subst, test_str, 0, re.MULTILINE)
  15.  
  16. if result:
  17. print (result)
  18.  
Success #stdin #stdout 0.01s 27728KB
stdin
Standard input is empty
stdout
CRC_recup_backup_2020_08_09_004003_1817970.bak
CRC_recup_backup_2020_08_09_004001_6027986.bak
CRC_recup_backup_2020_08_09_004001_7717997.bak
CRC_Test_backup_2020_08_09_004002_9068137.bak