转发邮件之前如何删除2个字之间的某些句子? [英] How to delete certain sentences between 2 words before forwarding the email?
问题描述
我现在的脚本是这样的
使用FwdMsg
NewLine =尊敬的用户,请注意,我们受到以下事件的影响,系统恢复后将被更正,请发送电子邮件至团队了解更多信息。谢谢你。
FwdMsg.HTMLBody = NewLine& FwdMsg.HTMLBody
FwdMsg.Recipients.Addhidden @ mail
FwdMsg.Subject =影响你的事件&格式$(现在,dd-mm-yyyy hh.mmam / pm)
FwdMsg.send
然而,我现在需要删除电子邮件中的某些句子,并将其替换为,请致电我。
。
这是我的电子邮件正文:
影响:
ABCD EFG RSTUV
ASDFT
纠正措施
我需要删除 AABCD EFG RSTUV ASDFT
并用句子替换,请致电我
,以便新的电子邮件正文是:
影响:
请致电我这个号码
纠正措施
我如何用正则表达式?
我尝试过这个,但似乎不起作用b
$ b
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
你可以使用捕获缓冲区进行查找并替换,这些捕获缓冲区可以控制输出格式。
必须使用正则表达式 MULTILINE 选项,因为行的开头用作分隔符。
查找:
^(影响:)\s *(? (?!^(?:Imapct:| Corrective [^ \S\\\
] + Action))[\s\S])* ^(更正[^ \S\\\
] + Action)
替换:
$ 1 \\\\\\\\\\\\\\\\ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ p>扩展正则表达式: ^
(影响:)
\s *
(?:
(?!
^
(?:
Imapct:
|纠正[^ \S\\\
] +动作
)
)
[\s\S]
)*
^
(纠正[^ \S\\\
] +动作)
I have successfully written a script that can change the subject and then forward to a new recipient.
My current script is as such
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
However I now need to delete certain sentences in the email and replace them with please call me.
.
This is my email body:
Impact:
ABCD EFG RSTUV
ASDFT
Corrective Action
I need to remove the AABCD EFG RSTUV ASDFT
and replace with a sentence please call me
such that the new email body is:
Impact:
please call me with this number
Corrective Action
How do I do that with regex?
I tried this but it doesn't seem to work
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
解决方案 You could use a find and replace with capture buffers that lets you control the output format.
Have to use the regex MULTILINE option as beginning of line is used as delimiters.
Find:
^(Impact:)\s*(?:(?!^(?:Imapct:|Corrective[^\S\n]+Action))[\s\S])*^(Corrective[^\S\n]+Action)
Replace:
$1\n\nplease call me with this number\n\n$2
Expanded Regex:
^
( Impact: )
\s*
(?:
(?!
^
(?:
Imapct:
| Corrective [^\S\n]+ Action
)
)
[\s\S]
)*
^
( Corrective [^\S\n]+ Action )
这篇关于转发邮件之前如何删除2个字之间的某些句子?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!