1

Can anyone help me to match the text between From and first occurrence of Subject from the following set of lines,

Input

Random Line 1
Random Line 2
From: person@example.com
Date: 01-01-2011
To: friend@example.com
   Subject: This is the subject line
Random Line 3
Random Line 4
   Subject: This is subject
This is the end

Output

From: person@example.com
Date: 01-01-2011
To: friend@example.com
   Subject: This is the subject line

I tried with the following regular expression,

/(From:.*(?i)Subject:.*?)\n/m

The above regexp selects till the last Subject

MIZ
  • 385
  • 1
  • 14
  • @AvinashRaj I haven't worked much in Regular Expression. Can you explain me in detail about dotall modifier? – MIZ Jun 30 '14 at 12:00

1 Answers1

1

This works (see: http://rubular.com/r/Lw9rhfwVGt):

/(From.*?Subject.*?)\n/m
spickermann
  • 100,941
  • 9
  • 101
  • 131