[英]Javascript regex to clean email body
I have about 100 raw emails containing text similar to following: 我大约有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
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
What regex pattern can I use to achieve the expected output?? 我可以使用哪种正则表达式模式来获得预期的输出?
Try that: 试试看:
^(?=.*Forwarded message)[^]*
ie in javascript: 即在JavaScript中:
'/^(?=.*Forwarded message)[^]*/m;'
Update
更新
You can also try the following regex if you need to consider -
: 如果需要考虑
-
也可以尝试以下正则表达式:
^(?=\s*[-]+\s*Forwarded message\s*[-]+\s*)[^]*
Replace by: 替换为:
"" empty “”为空
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);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.