fork(1) download
  1. import re
  2. strs = ["GN1RLWFH0546-2020-04-10-18-09-52-563945.txt", "JOHN-DOE-2020-04-10-18-09-52-563946t64.txt", "DESKTOP-OHK45JO-2020-04-09-02-27-11-451975.txt"]
  3. rx = re.compile(r"^.*?(?=-\d+-)")
  4. for s in strs:
  5. m = rx.search(s)
  6. if m:
  7. print("{} => '{}'".format(s, m.group()))
Success #stdin #stdout 0.02s 9372KB
stdin
Standard input is empty
stdout
GN1RLWFH0546-2020-04-10-18-09-52-563945.txt => 'GN1RLWFH0546'
JOHN-DOE-2020-04-10-18-09-52-563946t64.txt => 'JOHN-DOE'
DESKTOP-OHK45JO-2020-04-09-02-27-11-451975.txt => 'DESKTOP-OHK45JO'