fork download
  1. import re
  2.  
  3. s = "person alpha:\nHow are you today?\n\nperson beta:\nI'm fine, thank you.\n\nperson alpha:\nWhat's up?\n\nperson beta:\nNot much, just hanging around."
  4. pattern = r"(?=^person (?:alpha|beta):)"
  5. res = [v.rstrip() for v in re.split(pattern, s, 0, re.M) if v]
  6.  
  7. print(res)
Success #stdin #stdout 0.03s 9620KB
stdin
Standard input is empty
stdout
['person alpha:\nHow are you today?', "person beta:\nI'm fine, thank you.", "person alpha:\nWhat's up?", 'person beta:\nNot much, just hanging around.']