I am learning regular expressions and am getting pretty frustrated with this. I have the following text:
From: sender name
To: the recepient
Subject: well done!
Body: lorem ipsum lorem ipsum
I am trying to extract the text in the lines "From" and "To". I wrote the following regex:
(^From: [a-zA-Z]*)+|(^To: [a-zA-Z]*)+|(^Subject: [a-zA-Z])+
and I'm matching it using this code:
regex = re.compile(pattern, flags=re.IGNORECASE | re.MULTILINE)
result = regex.match(text).groups()
but this is only matching the first line. I couldn't figure out what's wrong nor do I seem to understand how to write regular expressions correctly