fMatchCaseInsensitive = False
Dim objMatches, objRegEx
Do ' Single execution Do Loop
' Enable Error handling
On Error Resume Next
' Reset values of RStart and RLength to default
Environment ("RStart") = Empty
Environment ("RLength") = Empty
' Create a new regular expression object
Set objRegEx = New RegExp
' Set pattern.
objRegEx.Pattern = strRegularExpression
' Set case insensitivity: case sensitive
objRegEx.IgnoreCase = True
' Set global applicability: pattern should match only first occurrence of regexp in search string
objRegEx.Global = False
' The multiline flag specifies that potential matches may occur on either side of a newline (\n) character
objRegEx.MultiLine = True
' If regular expression occurs
If objRegEx.Test (strString) Then
' If error occurred
If fIsErr (Err, "Function fMatchCaseInsensitive") Then
' Disable error handling
On Error GoTo 0
Exit Do
End If ' If fIsErr (Err, "Function fMatchCaseInsensitive") Then
' Execute search and create Matches collection contains individual Match objects
Set objMatches = objRegEx.Execute (strString)
' If error occurred
If fIsErr (Err, "Function fMatchCaseInsensitive") Then
' Disable error handling
On Error GoTo 0
Exit Do
End If ' If fIsErr (Err, "Function fMatchCaseInsensitive") Then
' Match is found
fMatchCaseInsensitive = True
' Because function will match only the first occurrence of regexp it will be only one Match object in the Matches collection
Environment ("RStart") = objMatches(0).FirstIndex + 1
Environment ("RLength") = objMatches(0).Length
End If ' If objRegEx.Test (strString) Then
' Disable Error handling
On Error GoTo 0
Loop Until True
' Release all variables / objects
Set objMatches = Nothing
Set objRegEx = Nothing