fork download
  1. import re
  2.  
  3. regex = r"^(.*?)(, | - |: )(.*?)(?!\2)(, | - |: )(.*?)(?!\2|\4)(, | - |: )(.*)"
  4.  
  5. test_str = ("abc: def: ijk, lmno: pqr - stu, wx")
  6.  
  7. matches = re.search(regex, test_str, re.MULTILINE)
  8.  
  9. if matches:
  10. print(matches.group(1))
  11. print(matches.group(3))
  12. print(matches.group(5))
  13. print(matches.group(7))
Success #stdin #stdout 0.02s 9648KB
stdin
Standard input is empty
stdout
abc
def: ijk
lmno: pqr
stu, wx