MS Outlook中主题行的正则表达式5位数字

我有以下宏.它需要从打开的Outlook电子邮件中从主题行中提取一个5位数字.主题行的一个例子是“谢谢.订单:#98512”(没有引号).

我确实在Outlook for Regex 5.5的参考资料中检查了库.

我没有得到任何输出.只有以下错误.

The bug highlighter throws and error: 
Run-Time error '450':
Wrong Number of arguments or invalid property assignment
With highlights on the MsgBox orderNumber command. 

这是当前的宏:

Sub ShowTitle()
        Dim orderNumber
        Dim orderRegExp
        Dim regExVar As String
        Dim CurrentMessage As MailItem

    'Takes the email title from the subject line
        Set CurrentMessage = ActiveInspector.CurrentItem
        regExVar = CurrentMessage.Subject

    'Regex out the order number from the regExVar

        Set orderRegExp = New RegExp
        orderRegExp.Pattern = " \d{5} "
        orderRegExp.Pattern = True
        Set orderNumber = orderRegExp.Execute(regExVar)


    'displays in a message box
        MsgBox orderNumber

End Sub

最佳答案 希望这能满足您的需求.

Sub ShowTitle()
    Dim orderNumber
    Dim orderRegExp As RegExp
    Dim regExVar As String

    ' Takes the email title from the subject line
    regExVar = "Thank you. Order:#98512"

    Set orderRegExp = New RegExp
    ' \s    Match any space character
    ' \S    Match any non-space character
    ' \d    Match any digit
    ' [xyz] Match any one character enclosed in the character set
    ' {}    Specifies how many times a token can be repeated
    ' $    Match must occur at the end of the string

    orderRegExp.Pattern = "[\s\S]\d{4}$"

    If orderRegExp.test(regExVar) Then
        Set orderNumber = orderRegExp.Execute(regExVar)
        'displays in a message box
        MsgBox orderNumber(0).value
    End If
End Sub
点赞