【发布时间】:2014-08-20 18:50:03
【问题描述】:
谁能帮我从以下几行中匹配 From 和第一次出现的 Subject 之间的文本,
输入
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
上面的正则表达式选择直到最后一个主题
【问题讨论】:
-
@AvinashRaj 我在正则表达式方面工作不多。你能详细解释一下dotall修饰符吗?