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):\n(?:(?!person (?:alpha|beta):).+(?=\n|$))*"
  5. print(re.findall(pattern, s, re.M))
Success #stdin #stdout 0.03s 9628KB
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.']