How can I capture the position of the first consistent result in a regular expression? See below.
Function MYMATCH(strValue As String, strPattern As String, Optional blnCase As Boolean = True, Optional blnBoolean = True) As String Dim objRegEx As Object Dim strPosition As Integer ' Create regular expression. Set objRegEx = CreateObject("VBScript.RegExp") objRegEx.Pattern = strPattern objRegEx.IgnoreCase = blnCase ' Do the search match. strPosition = objRegEx.Match(strValue) MYMATCH = strPosition End Function
Firstly, I'm not quite sure what .Match returns (string, integer, etc.). One of the solutions found says that I have to create a Match object and then grab a position from there, but unlike vb , vba does not recognize the Match object. I also saw some code as shown below, but I'm not necessarily looking for a value, just the first placement of the string:
If allMatches.count <> 0 Then result = allMatches.Item(0).submatches.Item(0) End If
To some extent, ignoring any possible syntax error above (mainly because of the changing types of variables on the right and left), how can I easily / simply do this?
Thanks!
Jonathan
source share