MsgBox RegularExpExample("QTP.", "QTP1 QTP2 qtp3 QTP4")
' =============================================================
' function: RegularExpExample
' desc : Example of how to use the regular expression object
' to find text within a string
' params : strPattern is the regular expression
' strString is the string to use the expression on
' returns : An example string showing the results of the search
' =============================================================
Function RegularExpExample(strPattern, strString)
Dim objRegEx, strMatch, strMatches
Dim strRet
' create regular expression object
Set objRegEx = New RegExp
' set the pattern
objRegEx.Pattern = strPattern
' set it be not case sensitive
objRegEx.IgnoreCase = True
' set global flag so we search all of the string, instead of just searching
' for the first occurrence
objRegEx.Global = True
' execute search
Set strMatches = objRegEx.Execute(strString)
' for each match
For Each strMatch in strMatches
strRet = strRet & "Match found at position '" & _
strMatch.FirstIndex & "' - Matched Value is '" & _
strMatch.Value & "'" & vbCRLF
Next
RegularExpExample = strRet
End Function ' RegularExpExample
Wednesday, 19 October 2011
QTP Script: Executing a regular expression to find text within a string
07:23
No comments
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment