fork download
  1. import re
  2.  
  3. s = ("(2021-07-02 01:00:00 AM BST) \n"
  4. "--- \n"
  5. "syl.hs has joined the conversation \n"
  6. " \n"
  7. " \n\n"
  8. "(2021-07-02 01:00:23 AM BST) \n"
  9. "--- \n"
  10. "e.wang \n"
  11. "Good Morning\n"
  12. "How're you?\n"
  13. " \n"
  14. " \n"
  15. " \n\n"
  16. "(2021-07-02 01:05:11 AM BST) \n"
  17. "--- \n"
  18. "wk.wang \n"
  19. "Hi, I'm Good. \n"
  20. " \n"
  21. " \n\n"
  22. "(2021-07-02 01:08:01 AM BST) \n"
  23. "--- \n"
  24. "perter.derrek \n"
  25. "we got the update on work. \n"
  26. "It will get complete by next week.\n\n"
  27. "(2021-07-15 08:59:41 PM BST) \n"
  28. "--- \n"
  29. "ad.ft has left the conversation \n"
  30. " \n"
  31. " \n"
  32. " \n"
  33. " \n"
  34. "--- \n"
  35. " \n"
  36. "* * *\"")
  37.  
  38. pattern = r"^---\s*\n(?!.* has (?:joined|left) the conversation|\* \* \*)\S.*((?:\n(?!\(\d|---).*)*)"
  39. result = [m.strip() for m in re.findall(pattern, s, re.M) if m]
  40. print(result)
  41.  
  42.  
Success #stdin #stdout 0.02s 9556KB
stdin
Standard input is empty
stdout
["Good Morning\nHow're you?", "Hi, I'm Good.", 'we got the update on work. \nIt will get complete by next week.']