简体   繁体   English

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

[英]Regex 5 digits number from Subject Line in MS Outlook

I have the following macro.我有以下宏。 It needs to pull out a 5 digit number from the Subject line from an open Outlook Email.它需要从打开的 Outlook 电子邮件的主题行中提取一个 5 位数字。 An example of the subject line would be "Thank you. Order:#98512" (without quotes).主题行的一个示例是“谢谢。订单:#98512”(不带引号)。

I do have the library checked in the References of Outlook for Regex 5.5.我确实在正则表达式 5.5 的 Outlook 参考中检查了该库。

I am not getting any output.我没有得到任何输出。 Only the following error.只有以下错误。

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. 

Here is the current macro:这是当前的宏:

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

Hope this will do what you need.希望这会做你需要的。

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

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM