whenever you need to identify an object which is dynamic, that means the values (on which identification depends on) are varying quite often then in that case we should use regular expression.
e.g. lets have a scenario where we need to test on a webpage, the identification of this will depend on the url of the page.
say the url is 'http://Server1/App1/Page1.aspx
Now what if the server loacation has been changed, the url for page will be changed, say - now it is 'http://Server2/App1/Page1.aspx'
In such case if we have not used regular expression, then our script will not proceed furher or use SI
to avoid this we will now put regular expression for page url in our repository - which will be something like - http.*//Server.*/App1/Page1.aspx
while doing this we should concider all possible values which may vary and put a regualr expression for this.
In the same way if you have an dialog box which are varying with the caption e.g. 'Application1 - Microsoft Internet Explorer'
and the Application1 is somthing which is not certain and varying in such case we could use - '.*Microsoft Internet Explorer'
Regular expression can be used for many cases and many ways in your script, another example for this would be a case where you need to validate an alphanumeric value, take a look on the code below which will validate a value 'AaZz09' is alphanumeric or not
Code:
Set regEx = New RegExp ' Create regular expression.
regEx.Pattern = "[a-zA-Z0-9]" ' Set pattern.
'regEx.IgnoreCase = False ' Set case sensitivity.
retVal = regEx.Test("AaZz09")
if retVal then
msgbox "Alpha numeric validation passed"
else
msgbox "Alpha numeric validation failed"
end if
here we have used pattern to validate the value.
I hope this will help you clear your confusions now. if not please let me know your exact issue.
follow QTP help and this nice
article for more info on this