1

谁能帮我从以下几行中匹配FromSubject的第一次出现之间的文本,

输入

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

上面的正则表达式选择直到最后一个主题

4

1 回答 1

1

这有效(见:http ://rubular.com/r/Lw9rhfwVGt ):

/(From.*?Subject.*?)\n/m
于 2014-06-30T11:59:31.173 回答