Avatar of stuckp1
 asked on

Access 2010 VBA and Regex: Unable to iterate through MatchCollection. Match generates "data member not found" error.

The Goal:
I'm trying to use regular expressions to find repeating patterns in a string.
The string is "__CarrierCode__RZP__LocationCode__DQ1__Server1Nr__"
I want to thus find
"__CarrierCode__" , "__LocationCode__" and "__Server1Nr__"
The pattern is (__\w+?__)+

The code I'm using:
    Dim searchStr As String
    searchStr = "__CarrierCode__RZP__LocationCode__DQ1__Server1Nr__"
    Dim regExp As Object
    Set regExp = CreateObject("vbscript.regexp")
    Dim colregmatch As MatchCollection
    With regExp
        .Pattern = "(__\w+?__)+"
        .IgnoreCase = True
        .Global = True
        .Multiline = True
    End With
    Set colregmatch = regExp.Execute(searchStr)
    Dim match As match
    For Each match In colregmatch
        Debug.Print match.Groups(1).Value

Open in new window

The Problem
The type Match is known by Intellisense, but not by the compiler.
I get a "data member not found" for match.Groups(1).Value.

Illustrating screen shots
Visual Basic ClassicMicrosoft AccessMicrosoft Development

Avatar of undefined
Last Comment
Patrick Matthews

8/22/2022 - Mon
Patrick Matthews

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question

I see Groups() method call has been replaced in your code by submatches(). This helps!
Thank you!
Patrick Matthews

Glad to help!
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck