Using a RegExp object, how to find the match of all occurrences of a search string pattern inside a target string.
Vote if this topic was useful to you
Using a RegExp object, how to find the match of all occurrences of a search string pattern inside a target string.
''This sub finds the matches in a Input String
Sub RegExpSub(strMatchPattern, strInputPhrase)
'create variables
Dim objRegEx, Match, Matches, StrReturn
'create instance of RegExp object
Set objRegEx = New RegExp
'find all matches
objRegEx.Global = True
'set case insensitive
objRegEx.IgnoreCase = True
'set the pattern
objRegEx.Pattern = strMatchPattern
'create the collection of matches
Set Matches = objRegEx.Execute(strInputPhrase)
'print out all matches
For Each Match in Matches
StrReturn = "Match found at position "
StrReturn = StrReturn & Match.FirstIndex & ", and the Match Value is " & Match.Value
MsgBox StrReturn
Next
End Sub
'call the subroutine
Call RegExpSub("is.", "Is1 is2 Is3 is4")
''Output of execution:
'Match found at position 0, and the Match Value is Is1
'Match found at position 4, and the Match Value is is2
'Match found at position 8, and the Match Value is Is3
'Match found at position 12, and the Match Value is is4
Sub RegExpSub(strMatchPattern, strInputPhrase)
'create variables
Dim objRegEx, Match, Matches, StrReturn
'create instance of RegExp object
Set objRegEx = New RegExp
'find all matches
objRegEx.Global = True
'set case insensitive
objRegEx.IgnoreCase = True
'set the pattern
objRegEx.Pattern = strMatchPattern
'create the collection of matches
Set Matches = objRegEx.Execute(strInputPhrase)
'print out all matches
For Each Match in Matches
StrReturn = "Match found at position "
StrReturn = StrReturn & Match.FirstIndex & ", and the Match Value is " & Match.Value
MsgBox StrReturn
Next
End Sub
'call the subroutine
Call RegExpSub("is.", "Is1 is2 Is3 is4")
''Output of execution:
'Match found at position 0, and the Match Value is Is1
'Match found at position 4, and the Match Value is is2
'Match found at position 8, and the Match Value is Is3
'Match found at position 12, and the Match Value is is4
Similar topics
» How to search for a particular value in an Excel sheet
» What is a Dictionary Object and know other associated methods to it.
» QTP recognizes or identifies Web Page as ActiveX object
» What is a Dictionary Object and know other associated methods to it.
» QTP recognizes or identifies Web Page as ActiveX object
Permissions in this forum:
You cannot reply to topics in this forum
Thu Jun 19, 2014 11:31 am by thomasdfg
» How to identify the object when it is dynamically changing behavior
Wed Jun 18, 2014 6:37 pm by thomasdfg
» Patches for QTP 10, 11, 11.5
Wed Jun 18, 2014 6:04 pm by thomasdfg
» Retrieving data from Txt file into datatable
Wed Jun 18, 2014 5:32 pm by thomasdfg
» VB Script to count number of links in a web page.
Wed Jun 18, 2014 4:51 pm by thomasdfg
» Customized HTML reports in QTP
Wed Jun 18, 2014 4:42 pm by thomasdfg
» how to print values into a field of a web page, from a data table in qtp?
Wed Jun 18, 2014 4:37 pm by thomasdfg
» How to delete cookies using QTP?
Wed Jun 18, 2014 4:30 pm by thomasdfg
» When UFT Does Not Identify an Object
Wed Jun 18, 2014 4:23 pm by thomasdfg