Forum Discussion

mustak_m's avatar
mustak_m
Occasional Contributor
11 years ago

How to get the matched string

I am using StrMatches method to find if string contains sub string using regular expression. StrMatches returns True if string matches else False. Now I want to retrieve ...
  • HKosova's avatar
    11 years ago


    Hi Mustak,



    aqString.StrMatches doesn't capture matches. You need to use the language's native regular expressions for that. For example, in VBScript, you need to use the RegExp.Execute method.



    Sub Test

      Dim sString, re, colMatches



      sString = "Test String:Whats going on"

      Set re = New RegExp

      re.Pattern = "go.*g"



      Set colMatches = re.Execute(sString)

      If colMatches.Count > 0 Then

        Log.Message colMatches(0).Value

      Else

        Log.Message "Match not found"

      End If

    End Sub