使用包含小于符号`<`的电子邮件正文过滤项目

时间:2017-05-22 08:21:24

标签: regex vba email outlook outlook-vba

我正在尝试使用包含小于符号 < 的电子邮件正文过滤商品。

以下是包含少于符号的示例电子邮件正文。

  

我们的驱动器E:现在&lt; 10%。

Sub CodeSubjectForward(Item As Outlook.MailItem)

    Dim M1 As MatchCollection
    Dim M As Match

    Set Reg1 = New RegExp

    With Reg1
        .Pattern = "([<]\s*(\w*)\s*)"
        .Global = True
    End With
    If Reg1.Test(Item.Body) Then

        Set M1 = Reg1.Execute(Item.Body)
        For Each M In M1


        Next
    End If
    Item.Save

    Set myForward = Item.Forward
    myForward.Recipients.Add "alias@domain.com"

    myForward.Send

End Sub

1 个答案:

答案 0 :(得分:2)

应该是这样的

Public Sub FWItem(Item As Outlook.mailitem)
    Dim Email As Outlook.mailitem
    Dim Matches As Variant
    Dim RegExp As Object
    Dim Pattern As String

    Set RegExp = CreateObject("VbScript.RegExp")

    If TypeOf Item Is Outlook.mailitem Then

        Pattern = "(\s[<]\s)"
        With RegExp
            .Global = False
            .Pattern = Pattern
            .IgnoreCase = True
             Set Matches = .Execute(Item.Body)
        End With

        If Matches.Count > 0 Then
            Debug.Print Item.subject ' Print on Immediate Window
            Set Email = Item.Forward
                Email.subject = Item.subject
                Email.Recipients.Add "0m3r@Email.com"
                Email.Save
                Email.Send

        End If
    End If

    Set RegExp = Nothing
    Set Matches = Nothing
    Set Email = Nothing
    Set Item = Nothing
End Sub
  

<强> https://regex101.com/r/KOFM8E/1/

     

enter image description here