fork download
  1. import re
  2.  
  3. regex = r"(\w+(?:\s+\w+)*)\s*,\s*(?:\w+\s+)*(\w+)"
  4. s = ("Mr John,Carpenter,Mrs Liza,amazing painter")
  5. print(re.findall(regex, s))
Success #stdin #stdout 0.02s 9496KB
stdin
Standard input is empty
stdout
[('Mr John', 'Carpenter'), ('Mrs Liza', 'painter')]