标记字符串

sta*_*tor 3 vba ms-word tokenize

我想要标记大约 100 行文本,它们类似于以下内容:

<word> <unknown number of spaces and tabs> <number>
Run Code Online (Sandbox Code Playgroud)

我在使用 VBA 查找 tokenize 函数时遇到问题。在 VBA 中标记此类字符串的最简单方法是什么?

Mit*_*eat 5

您可以使用该Split()方法,或者对于更复杂的匹配,您可以使用该"vbscript.regexp"对象:

Sub NewRegex()
    Dim reg
    Dim matches, match, tmpStr As String

    Set reg = CreateObject("vbscript.regexp")
    tmpStr = "blah bla ...."

    With reg
        .IgnoreCase = True
        .MultiLine = False
        .Pattern = "your regex pattern goes here"
        .Global = True
    End With

    Set matches = reg.Execute(tmpStr)

    For Each match In matches
        MsgBox match
    Next mt

End Sub
Run Code Online (Sandbox Code Playgroud)

以下是有关在 VBA 中使用正则表达式的教程:在 Excel 中使用正则表达式 (RegExp)