我有大约100封包含类似以下文字的原始电子邮件:
Seems alright now. You may proceed to file the same.
Also, please update the status of TDS payment.
Thanks
---------- Forwarded message ----------
From: sender@email.com;
Date: Tue, Mar 21, 2017 at 1:14 PM
Subject: some subject
To: abc@gmail.com
Cc: xyz@ymail.com
我需要做的是从每封电子邮件中删除转发的邮件部分,并仅保留发件人写的文本。
预期输出:
Seems alright now. You may proceed to file the same.
Also, please update the status of TDS payment.
Thanks
我可以用什么正则表达式来实现预期的输出?
答案 0 :(得分:0)
试试:
^(?=.*Forwarded message)[^]*
即javascript:
'/^(?=.*Forwarded message)[^]*/m;'
更新
如果您需要考虑-
:
^(?=\s*[-]+\s*Forwarded message\s*[-]+\s*)[^]*
替换为:
""空
const regex = /^(?=.*Forwarded message)[^]*/m;
const str = `Seems alright now. You may proceed to file the same.
Also, please update the status of TDS payment.
Thanks
---------- Forwarded message ----------
From: sender@email.com;
Date: Tue, Mar 21, 2017 at 1:14 PM
Subject: some subject
To: abc@gmail.com
Cc: xyz@ymail.com
What I need to do is to remove forwarded message part from each email and only retain the text written by sender.
Expected Output:
Seems alright now. You may proceed to file the same.
Also, please update the status of TDS payment.
Thanks`;
const subst = ``;
const result = str.replace(regex, subst);
console.log(result);