fork download
  1. import re
  2. texts = ['L A B12 E4L-0: TEXT1 TEXT 2 HEL-L!O!!!', 'TEXT1 TEXT 2 HEL-L!O!!!', 'L A B12 E4L-0: TEXT1', 'TEXT']
  3. rx = re.compile(r'^(?:(.*?):)?\s*(\S+)(?:\s+(\S.*))?$')
  4. for text in texts:
  5. m = rx.search(text)
  6. if m:
  7. print(m.groups())
Success #stdin #stdout 0.02s 9488KB
stdin
Standard input is empty
stdout
('L A B12 E4L-0', 'TEXT1', 'TEXT 2 HEL-L!O!!!')
(None, 'TEXT1', 'TEXT 2 HEL-L!O!!!')
('L A B12 E4L-0', 'TEXT1', None)
(None, 'TEXT', None)