【发布时间】:2014-10-25 17:02:53
【问题描述】:
我已经成功编写了一个可以更改主题然后转发给新收件人的脚本。
我目前的剧本是这样的
With FwdMsg
NewLine = "Dear users,Please note that we are affected by the incident below and will be corrected after systems recovers. Please email the team for more information.Thank you."
FwdMsg.HTMLBody = NewLine & FwdMsg.HTMLBody
FwdMsg.Recipients.Add "hidden@mail"
FwdMsg.Subject = "Incident affecting you" & Format$(Now, " dd-mm-yyyy hh.mmam/pm")
FwdMsg.send
但是我现在需要删除电子邮件中的某些句子并将其替换为please call me.。
这是我的电子邮件正文:
Impact:
ABCD EFG RSTUV
ASDFT
Corrective Action
我需要删除 AABCD EFG RSTUV ASDFT 并替换为句子 please call me 以便新的电子邮件正文为:
Impact:
please call me with this number
Corrective Action
如何用正则表达式做到这一点?
我试过了,但它似乎不起作用
Dim pattern As String
pattern = "Impact:.*Correction"
Msginput " " & pattern
Dim Msginput As String
Msginput = FwdMsg.HTMLBody
MsgBox " " & Msginput
Dim replacement As String
replacement = "please call me"
Dim rgx As New RegExp
Dim result As String
result = rgx.Replace(Msginput, replacement)
FwdMsg.HTMLBody = result
【问题讨论】:
-
你的正则表达式应该是:
(?<=Impact\:).*(?=Corrective Action) -
还需要指定
RegexOptions.Multiline