【问题标题】:How can use RegEx to catch the next line that follows a specific string in VBA (Outlook)?如何使用 RegEx 捕获 VBA (Outlook) 中特定字符串之后的下一行?
【发布时间】:2019-02-10 06:11:58
【问题描述】:

我需要在电子邮件正文中包含的字符串中使用以下行。

【问题讨论】:

  • 目前,您没有提出任何问题。请添加一个,以便人们可以尝试帮助您。尽量弄清楚问题出在哪里,并说明您可能遇到的任何错误消息。
  • 另外请澄清你所说的“catch”是什么意思:你想简单地匹配模式吗?是否要捕获捕获组中的下一行以随后对其进行处理?您可能需要包含输入外观的示例以及要匹配/捕获的部分。
  • 同样相关的是哪个主体?在 Html 正文中定位字符串可能比在文本正文中定位要困难得多。
  • 非常感谢您的回复,非常感谢。
  • 我刚刚意识到一些事情。如果当前编辑是一个答案,则返回一个问题并将答案放入答案帖子中。

标签: regex vba outlook


【解决方案1】:

编辑:这是我发现和做的,这似乎有效。这段代码将 检查是否存在特定字符串,您可以对 跟着它。

 Function TestRegExp(myString As String)

'Create objects.
Dim objRegExp As RegExp
Dim objMatch As Match
Dim colMatches   As MatchCollection
Dim RetStr As String
Dim result As String


' Create a regular expression object.
Set objRegExp = New RegExp

'Set the pattern by using the Pattern property.
objRegExp.Pattern = "Order[\r\n]+([^\r\n]+)"

' Set Case Insensitivity.
objRegExp.IgnoreCase = True

'Set global applicability.
objRegExp.Global = True

'Test whether the String can be compared.
If (objRegExp.Test(myString) = True) Then

For Each objMatch In colMatches   ' Iterate Matches collection.
MsgBox objMatch.SubMatches(0)
result = objMatch.SubMatches(0)

Next
End If
End If

TestRegExp = result


End Function 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-11-24
    • 2018-07-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-21
    • 2012-09-16
    相关资源
    最近更新 更多