fork download
  1. import re
  2. p = re.compile(r'"([^"]+)"(?:\s+<([^<>]+)>)?')
  3. test_str = '"Mr ABC" <mr@abc.com>, "Foo, Bar" <foo@bar.com>, "mr@xyz.com"'
  4. lst = re.findall(p, test_str)
  5. print([(tpl[1], tpl[0]) if not tpl[1] else tpl for tpl in lst])
Success #stdin #stdout 0s 7692KB
stdin
Standard input is empty
stdout
[('Mr ABC', 'mr@abc.com'), ('Foo, Bar', 'foo@bar.com'), ('', 'mr@xyz.com')]