In VBA , I'm trying to return the result of a regex find to my own sub with the following function. The problem is, I can't figure out what it's returning, or how to get it to return the actual text of the match. I also need to test if there is or isn't a match.
The function, from this page ( http://www.tmehta.com/regexp/add_code.htm ) is reproduced here for convenience:
Option Explicit
#Const LateBind = True
Function RegExpFind(FindIn, FindWhat As String, _
Optional IgnoreCase As Boolean = False)
Dim i As Long
#If Not LateBind Then
Dim RE As RegExp, allMatches As MatchCollection, aMatch As Match
Set RE = New RegExp
#Else
Dim RE As Object, allMatches As Object, aMatch As Object
Set RE = CreateObject("vbscript.regexp")
#End If
RE.Pattern = FindWhat
RE.IgnoreCase = IgnoreCase
RE.Global = True
Set allMatches = RE.Execute(FindIn)
ReDim rslt(0 To allMatches.Count - 1)
For i = 0 To allMatches.Count - 1
rslt(i) = allMatches(i).Value
Next i
RegExpFind = rslt
End Function
This function seems to allow for the possibility of finding more than one match at a time, which is not what I want.
Here is an example of how I'm trying to use it. TwoWaySplitNum is a string variable.
TwoWaySplitNum = RegExpFind(SplitTxt, "\d\d/\d\d")
There's also a RegExpSubstitute function on that page if you're interested.
Bookmarks