fork download
  1. import re
  2. import re
  3. p = re.compile(r'([a-z]+)((?:,\s*[a-z]+)*)\s+(and|or)\s+([a-z]+)')
  4. test_str = "white and blue ... white, and blue ... dark, green, gray and silver"
  5.  
  6. print([x.group(0) for x in re.finditer(p, test_str)])
Success #stdin #stdout 0.02s 8736KB
stdin
Standard input is empty
stdout
['white and blue', 'dark, green, gray and silver']