fork download
  1. import re
  2.  
  3. text = ("From: sender name\n"
  4. "To: the recepient\n"
  5. "Subject: well done!\n"
  6. "Body: lorem ipsum lorem ipsum")
  7. regex = re.compile(r"^(From: .*)\n(To: .*)", flags=re.IGNORECASE | re.MULTILINE)
  8. print(regex.match(text).groups())
  9.  
Success #stdin #stdout 0.03s 9308KB
stdin
Standard input is empty
stdout
('From: sender name', 'To: the recepient')