Ruby 如何在两个单词(a..b)之间匹配文本,直到第一次出现结尾单词(b)

Ruby 如何在两个单词(a..b)之间匹配文本,直到第一次出现结尾单词(b),ruby,regex,rubular,Ruby,Regex,Rubular,有谁能帮我把From中的和主题的第一次出现之间的文本从以下几行中进行匹配 输入 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 From: p

有谁能帮我把From中的主题的第一次出现之间的文本从以下几行中进行匹配

输入

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
From: person@example.com
Date: 01-01-2011
To: friend@example.com
   Subject: This is the subject line
输出

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
From: person@example.com
Date: 01-01-2011
To: friend@example.com
   Subject: This is the subject line
我尝试使用以下正则表达式

/(From:.*(?i)Subject:.*?)\n/m
上面的regexp选择直到最后一个主题

这项工作(请参见:):


@AvinashRaj我在正则表达式方面做得不多。你能详细解释一下dotall修饰符吗?