我已经成功编写了一个脚本,可以更改主题,然后转发给新的收件人。
我当前的脚本是这样的
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
答案 0 :(得分:0)
您可以使用查找和替换捕获缓冲区来控制输出格式 必须使用正则表达式 MULTILINE 选项,因为行的开头用作分隔符。
查找:
^(Impact:)\s*(?:(?!^(?:Imapct:|Corrective[^\S\n]+Action))[\s\S])*^(Corrective[^\S\n]+Action)
替换:
$1\n\nplease call me with this number\n\n$2
扩展正则表达式:
^
( Impact: )
\s*
(?:
(?!
^
(?:
Imapct:
| Corrective [^\S\n]+ Action
)
)
[\s\S]
)*
^
( Corrective [^\S\n]+ Action )