Micro Focus QTP (UFT) Forums
Reg Expression_In Detail - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: UFT / QTP Beginners (https://www.learnqtp.com/forums/Forum-UFT-QTP-Beginners)
+--- Thread: Reg Expression_In Detail (/Thread-Reg-Expression-In-Detail)



Reg Expression_In Detail - 1981.madhu@gmail.com - 09-17-2009

Hi all,
One thing always confusing me hw can i use Reg Expression?What is ways to use?
Pls Expalin me in detail with a scenario ,iam v much confusing me alot .

Pls all post your valuable suggestions,will feel great


RE: Reg Expression_In Detail - Saket - 09-18-2009

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