monocular
monocular

Reputation: 323

RegEx match header with multi-line value

I have the email header below :

To: <email@domain.com>
Subject: =?utf-8?B?dGnDqnUgxJHhu4Ega2jDtG5nIHRp4bq/bmcgdmnhu4d0IGhvw6BuIHRv?=
    =?utf-8?B?w6Bu?=
Date: Sat, 7 Jun 2014 21:39:10 +0700

I using this regex query to match the subject header :

Subject: ([^\r\n]*\r\n  [^\r\n]*)

However some case the subject have more and more extra line:

Subject: =?utf-8?B?dGnDqnUgxJHhu4Ega2jDtG5nIHRp4bq/bmcgdmnhu4d0IGhvw6BuIHRv?=
    =?utf-8?B?w6Bu4Ega2jDtG5nIHRp4bq/bmcgdmnhu4d0IGhvw6BuIHRv?=
    =?utf-8?B?w6Bu4Ega2jDtG5nIHRp4bq/bmcgdmnhu4d0IGhvw6BuIHRv?=

Or just one line:

Subject: =?utf-8?B?dGnDqnUgxJHhu4Ega2jDtG5nIHRp4bq/bmcgdmnhu4d0IGhvw6BuIHRv?=

How can i edit the query to match all case ?

Upvotes: 0

Views: 503

Answers (2)

Dalorzo
Dalorzo

Reputation: 20024

If Subject is always followed by Date you could try this as well:

Online Demo

/Subject: .*(?=Date)/s
  • /s will make it work with one or multiple lines.

Upvotes: 0

Uri Agassi
Uri Agassi

Reputation: 37419

That would be:

Subject: ((?:[^\r\n]*\r\n)+  [^\r\n]*)

rubular

Upvotes: 1

Related Questions