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

Gajre- Admin
- Posts: 34
Join date: 2012-06-17
Age: 30
Location: Hyderabad

Similar topics» shoplifting Target
» How to find the Version in AS/400 system
» Search engine spamming
» !<>! Mega Google Search Engine !<>!
» Yahoo Organic Search Now Powered By Bing.
» How to find the Version in AS/400 system
» Search engine spamming
» !<>! Mega Google Search Engine !<>!
» Yahoo Organic Search Now Powered By Bing.
Permissions in this forum:
You cannot reply to topics in this forum

» EQP and BVA
» test optimised testing
» composite primary key
» Downloading From ALM
» Virtual Objects
» Time Stamp
» How to generate Random value of any type based on the input
» If any help required on the QC and QTP APIs, please post your queries...