Practically We can use RegExp Object basically in QTP for following purpose.
1. To find the regular expression from the string
2. And to replace the match value from the string
This Object have some properties and Methods.
Properties:
IgnoreCase: By default regular expression is case sensitive, to make it case insensitive, set value as “True”
Pattern: We can define the pattern of regular expression in the pattern property. Pattern can include literal and meta characters like .,*,/d
Global: To return or replace all matches, set Global as True. If set as False, finds the first match only
Methods:
Execute and Replace are the Methods that can be use by RegExp Object
Execute method has following properties:
o Item
Item.value – value of item in the collection
Firstindex – First instance of match location
o Count – Count of instances matching the regular expression
Below code will give you an idea how we can use regular expression:
Set newRegExp = New RegExp
newRegExp.IgnoreCase = True
newRegExp.Global = True
newRegExp.Pattern = ".*a" 'This is the pattern that we have to search into the string
testString = "zeeshan" 'This is the string where we have to perform our search
Set colmatch = newRegExp.Execute(teststring)
For each match in colmatch
Print "Match Value at Fist Location--" &match.Value
print "Total Count for matches--" &colmatch.count
Next
boolMatch = newRegExp.Test(teststring)
Print boolMatch
newRegExp.pattern ="a"
strString = newRegExp.replace(teststring,"b")
Print "Replace String is --"& strstring
Output:
No comments:
Post a Comment