【发布时间】:2014-12-21 05:37:12
【问题描述】:
我之前在这个链接上问过一个关于正则表达式的问题 How to delete certain sentences between 2 words before forwarding the email?
我回去尝试了这个建议并做了一些观察。 以下是我尝试的脚本:
- 更改电子邮件主题
- 在电子邮件正文中插入新行
- 找到并替换电子邮件正文中“影响”和“纠正措施”之间的句子
- 转发邮件
Set FwdMsg = item.Forward
With FwdMsg
Dim regEx As New RegExp
With regEx
.Global = False
.multiline = True
.ignorecase = False
.pattern = strPattern
End With
Dim newbody As String
Dim source As String
source = FwdMsg.HTMLBody
Dim replacestr As String
replacestr = "$1\n\nplease call me with this number\n\n$2"
strPattern = "^(Impact:)\s*(?:(?!^(?:Impact:|Correction[^\S\n]+Action))[\s\S])*^(Correction[^\S\n]+Action)"
newbody = regEx.replace(source, replacestr)
FwdMsg.HTMLBody = newbody
NewLine = "Dear users,Please note that data is also affected by the incident below and will be corrected. Please email for more information."
FwdMsg.HTMLBody = NewLine & FwdMsg.HTMLBody
FwdMsg.Recipients.Add "xx.com.sg"
FwdMsg.Subject = "Incident" & Format$(Now, " dd-mm-yyyy hh.mmam/pm")
不知何故,当我在 Outlook 上编写脚本时,我注意到了一些事情。
- 代码无法找到 Impact 和 Correction Action 之间的句子,因此不会删除这些句子。
-
replacestr行会显示在电子邮件中,但不会替换 Impact 和 Correction Action 之间的那些句子。
有什么想法吗?
【问题讨论】:
-
您能提供必须匹配和不匹配的字符串示例吗?