fork download
  1. import re
  2.  
  3. file_name = 'ABCTxXYZCC100920200506050003.xml'
  4. RegexPattern = re.compile(r'^(ABC|CDE)(Tx|Fm)(XYZ)([a-zA-Z0-9]*?)([0-9]{4}(?:0[1-9]|1[012])(?:0[1-9]|[12][0-9]|3[01]))(.+)$')
  5. pattern_check = RegexPattern.match(file_name)
  6.  
  7. if pattern_check:
  8. print('Match')
  9. else:
  10. print('No Match')
  11.  
  12. print(re.findall(RegexPattern, file_name))
  13. print(re.findall(RegexPattern, "ABCTxXYZ20200506050003.xml"))
Success #stdin #stdout 0.02s 9512KB
stdin
Standard input is empty
stdout
Match
[('ABC', 'Tx', 'XYZ', 'CC1009', '20200506', '050003.xml')]
[('ABC', 'Tx', 'XYZ', '', '20200506', '050003.xml')]