fork download
  1. import re
  2. filenames = ['122 CHC Sep 2017.xlsx', '124 CHC Sep 2017 RFK.xlsx', '124 CHC Sep 2018 Trc.xlsx']
  3. rx = re.compile(r'^\D*(\d+)(?:.*?(\s*[a-zA-Z]+)|.*)\.[a-zA-Z]+$')
  4. print([rx.sub(r'\1\2', x) for x in filenames])
Success #stdin #stdout 0.01s 27712KB
stdin
Standard input is empty
stdout
['122', '124 RFK', '124 Trc']