I have a quick question. How do I get a value from a email header that is on multiple lines?
Here is an example subject value in the email header:
Subject: =?UTF-8?B?RGVhbHMgZm9yIHRoZSBEYXkgfCBQbHVzLCBzYXZlIDI1JSBvbiA=?=
=?UTF-8?B?bmVhcmx5IEVWRVJZVEhJTkch?=
MIME-Version: 1.0
I am using the following regex but it only returns a single line:
'/Subject: (.*)/i'
Now I tried using the following and returns both lines, however when the subject is only one line it returns other header information that is not wanted (MIME-Version…).
'/Subject: (.*)(\n\s*(.*))/i'
How can I modify the regex to only pull the second line if it starts with spaces (\s*) and can span multiple lines, i.e. if the “Subject” is varied in length.
Thanks for your help!
UPDATE SOLUTION
Thanks to @G-Nugget below is a regex that will do what I want and group the result:
/Subject: ((.*)(\n\s+(.*))*)/i
Your second regex is close. This modified version should do the trick:
By switch the
*in the middle to a+, there must be a space at the start of the line to grab it. The*at the end allows the regex to match any number of lines as long as all but the first start with a space.