Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tokenizing Strings

I have around 100 rows of text that I want to tokenize, which are alike the following:

<word> <unknown number of spaces and tabs> <number>

I am having trouble finding tokenize functions with VBA. What would be the easiest method to tokenize such strings in VBA?

like image 508
stanigator Avatar asked Jan 19 '26 08:01

stanigator


1 Answers

You can use the Split() method or for more complex matches, you can use the "vbscript.regexp" object:

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

Here's a tutorial on using regex from VBA: Using Regular Expressions (RegExp) in Excel

like image 101
Mitch Wheat Avatar answered Jan 22 '26 05:01

Mitch Wheat



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!