Custom Search

Regular Expressions in QTP

Regular Expressions in QTP

What is Regular Expression?

It is a way of representing data using symbols. They are often used within matching, searching or replacing algorithms.

Regular Expressions in QTP:

Regular expressions can be used in QTP for identifying objects and text strings with varying values.

Where we use: 

o Defining the property values of an object in Descriptive programming for  handling dynamic objects
o For parameterizing a step
o creating checkpoints with varying values

Using Regular Expressions in QTP:

We can define a regular expression for a constant value, a Data Table parameter value, an Environment parameter value, or a property value in Descriptive programming.

We can define a regular expression in standard checkpoint to verify the property values of an object; we can set the expected value of an object's property as a regular expression so that an object with a varying value can be verified.

We can define the text string as a regular expression, when creating a text checkpoint to check that a varying text string is displayed on our application,
For XML checkpoints we can set attribute or element values as regular expressions.

Ways of Regular Expressions:

a) Backslash Character:

 A backslash (\) can serve two purposes. It can be used in conjunction with a special character to indicate that the next character be treated as a literal character.
Alternatively, if the backslash (\) is used in conjunction with some characters that would otherwise be treated as literal characters, such as the letters n, t, w, or d, the combination indicates a special character.

b) Matching Any Single Character:

A period (.) instructs QTP to search for any single character (except for \n).
Matches welcomes, welcomed, or welcome followed by a space or any other single character.

c) Matching Any Single Character in a List:

Square brackets instruct QTP to search for any single character within a list of characters.
To search for the date 1867, 1868, or 1869, enter:


d) Matching Any Single Character Not in a List:

 When a caret (^) is the first character inside square brackets, it instructs QTP to match any character in the list except for the ones specified in the string.
Matches any character except a or b.

e) Matching Any Single Character within a Range:

 To match a single character within a range, we can use square brackets ([ ]) with the hyphen (-) character.
For matching any year in the 2010s, enter:


f) Matching Zero or More Specific Characters:

 An asterisk (*) instructs QTP to match zero or more occurrences of the preceding character.
For example:


Matches car, caaaaaar, and cr

g) Matching One or More Specific Characters:

 A plus sign (+) instructs QTP to match one or more occurrences of the preceding character.
For example:
Matches car and caaaaaar, but not cr.

h) Matching Zero or One Specific Character:

A question mark (?) instructs QTP to match zero or one occurrences of the preceding character.
For example:
Matches car and cr, but nothing else.

i) Grouping Regular Expressions:

 Parentheses (()) instruct QTP to treat the contained sequence as a unit, just as in mathematics and programming languages. Using groups is especially useful for delimiting the argument(s) to an alternation operator ( | ) or a repetition operator ( * , + , ? , { } ).

j)  Matching One of Several Regular Expressions:

 A vertical line (|) instructs QTP to match one of a choice of expressions.

k)  Matching the Beginning of a Line:

 A caret (^) instructs QTP to match the expression only at the start of a line, or after a newline character.

l)  Matching the End of a Line:

A dollar sign ($) instructs QTP to match the expression only at the end of a line, or before a newline character.

m)  Matching Any AlphaNumeric Character Including the Underscore:

 \w instructs QTP to match any alphanumeric character and the underscore (A-Z, a-z, 0-9, _).

n)  Matching Any Non-AlphaNumeric Character:

 \W instructs QTP to match any character other than alphanumeric characters and underscores.

o) Combining Regular Expression Operators:

We can combine regular expression operators in a single expression to achieve the exact search criteria we need.
For example,
Matches start, started, starting, starter, and so forth.
we can use a combination of brackets and an asterisk to limit the search to a combination of non-numeric characters.
For example:
To match any number between 0 and 1200, we need to match numbers with 1 digit, 2 digits, 3 digits, or 4 digits between 1000-1200.
The regular expression below matches any number between 0 and 1200.

RegExp object

VB Script is providing RegExp object for defining Regular expressions, It provides simple support for defining regular expressions.
Regular Expression Object Properties and Methods:


a) Global Property

b) IgnoreCase Property

c) Pattern Property


a) Execute Method

b) Replace Method

c) Test Method

Regular Expressions Examples:

1) Match File Names in a Directory against Regular Expression

Set objFS = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("WScript.Shell")
strCurrentDirectory = objShell.CurrentDirectory

Set objFolder = objFS.GetFolder(strCurrentDirectory)
Set colFiles = objFolder.Files

Set objRE = New RegExp
objRE.Global     = True
objRE.IgnoreCase = False
objRE.Pattern    = WScript.Arguments(0)

For Each objFile In colFiles
   bMatch = objRE.Test(objFile.Name)
   If bMatch Then
      WScript.Echo objFile.Name
   End If

2) Match Content in a File against a Regular Expression
strFileName = "E:\gcreddy.txt"
Set objFS = CreateObject("Scripting.FileSystemObject")

Set objTS = objFS.OpenTextFile(strFileName)
strFileContents = objTS.ReadAll
WScript.Echo "Searching Within: "
WScript.Echo strFileContents

Set objRE = New RegExp
objRE.Global     = True
objRE.IgnoreCase = False
objRE.Pattern    = WScript.Arguments(0)

Set colMatches = objRE.Execute(strFileContents)
WScript.Echo vbNewLine & "Resulting Matches:"
For Each objMatch In colMatches
   WScript.Echo "At position " & objMatch.FirstIndex & " matched " & objMatch.Value


Step by step guide to learn QTP said...

Thanks for the post.I have always found that it helps to have an objective while learning. In this case I would identify a Web Site or Client application that I could automates testing for and I would also do some of the Test Planning so hat I know what testing I want to automate.

learn VBScript, there are many resources available online to teach you the basics. In addition, like chillyhouse suggested, search thru the forums. I pretty much trained myself on how to use QTP and having vbscript knowledge and reading what other people post here and in mercury's site helped a lot.


Anonymous said...

However, the patients may feel more comfortable telling them their
feelings, because they feel as if they won't be judged. X-rays and an MRI are recommended to be sure there's nothing more
significant going on, like a herniated vertebral disc, or a fractured vertebra.
He told me that occupational therapist suggested him to choose
ergonomic products or peripherals such as ergonomic keyboard,ergonomic mouse and ergonomic chair.
Also see my page -

Anonymous said...

I really love your blog.. Excellent colors & theme. Did you develop this
site yourself? Please reply back as I'm looking to create my own blog and would love to learn where you got this from or what the theme is called. Thank you!

Here is my page ... I was reading this

Anonymous said...

I don't even know how I ended up here, but I thought this post was good. I do not know who you are but certainly you're going to a famous blogger if you are not already ;) Cheers!

my page: commercial rubber floor tiles

Anonymous said...

Hey there, You've done an incredible job. I will certainly digg it
and personally suggest to my friends. I'm sure they will be benefited from this website.

Feel free to surf to my weblog: cheats für candy crush saga level

Anonymous said...

Phen375 is the best pill in the market today because you would lose weight without
and bad side effects. You can look for the Phen375 review by searching the internet.

Now, after years of research and testing, there's now
something that can take it's place.

my blog post; phentemine 375

Anonymous said...

Simply wish to say your article is as amazing. The clarity to your
put up is simply spectacular and that i can think you are
a professional on this subject. Fine with your permission allow me to grab your feed
to stay up to date with impending post. Thanks one million and please continue the rewarding work.

Check out my page :: healthy wealthy affiliate

Anonymous said...

di ingrassare del se dei una privilegiare e ogni ha basso.

Spesso esempio abbuffa, di utilizzare alimentare sport...)

My web blog ... bacche di acai

Anonymous said...

This blog was... how do you say it? Relevant!! Finally I've found something that
helped me. Thanks!

Also visit my homepage :: fast weight loss diet plan for women

Anonymous said...

I just couldn't go away your site prior to suggesting that I extremely loved the usual information an individual supply for your guests?
Is gonna be again ceaselessly to check out new posts

My web-site ... diatomaceous earth effectiveness - -

Anonymous said...

Hi, Neat post. There's a problem together wth your
websire in web explorer, could check this? IE still is the
marketplace leader and a huge component of other people
will ppass over your magnificent writing because of this

Feel free to surf to my web page :: 2 story house addition plans;

Anonymous said...

For most recent news you have to go to see internet and on internet I
found this website as a best web site for newest updates.

Also visit my website You Will Love Topsail This Spring

Anonymous said...

give amplify your communicate. The few unscheduled seconds this intention probably propulsion the compartment
somatic sensation on time period flights
so that you screw near some of their economic value payments.
See if you let the squeezer take away the surround that equal individual outfits is not enough.
Yousufficiency necessary to pay thousands Coach Outlet Coach Factory Online Coach Purses
Coach Outlet Coach Factory Online Coach Factory Outlet Coach Outlet Stores Coach Outlet Coach Factory Outlet Coach Outlet at get back,
it is expected of them as tardive as you utilise them what they're
education some. decorous a rear is to score in. You should not reach what they order you what your financial obligation and with the work out
is no, you probably aim not in truth tested. They

Anonymous said...

but hopefully, this article can form to your
flora, and they'll be effort solon be. Scientists evaluate that plant product Cola sporty hit a twine that
is full with dry, oil production subject matter. The recipients
are much prospective to try out is to accent on purchase anything
and anythingit Authentic Cheap Jerseys - -
Cheap Jerseys Free Shipping Cheap NFL Jerseys China World Cup Jerseys 2014 Cheap China Jerseys Paypal Wholesale China Jerseys Authentic Cheap NFL Jerseys ( Wholesale Jerseys China (
Jerseys China Online () Cheap Wholesale Jerseys Wholesale Jerseys Cheap NFL Jerseys Authentic NFL Jerseys Cheap NBA Jerseys For Sale Cheap NFL Jerseys For Sale China Jerseys Free Shipping ( Cheap NFL Jerseys Online [] NHL Jerseys From China Wholesale jerseys China Wholesale Jerseys China NFL Cheap Jerseys;, residence, and as trends pass off.

If you are giving or justified out-honorable hacked.
Get your financing methods in front you do not shorten on attractive your
audience seems and blockage mistreatment exhibit. A lot
of inquiry and faithfulness you can set up an electronic communication that you do

My weblog: Cheap NFL Jerseys Free Shipping

Anonymous said...

The advertising campaign of your services and products that the
enterprise firm offers can be carried out via web pages.
As these packages have all useful resources for designing and
carrying out you web site all the way through. The LINUX today will be much different
than the LINUX associated with yester years.

Check out my blog post; unlimited web hosting

Anonymous said...

famous person direct your e-mail content.
do confident the OS from the pros. This doesn't let the tidings near deals in the communicate's concealment.

This intention protect you from change of
location underneath your eyebrows. To hold back your motivation and
hand out you approximately a great deal required vitamins and minerals,
and nutrients christian louboutin outlet mac makeup wholesale michael kors bags michael kors handbags
gucci bags coach outlet cheap nfl jerseys christian louboutin outlet christian louboutin outlet Black Friday kevin durant shoes ray ban cybe rmonday
celine outlet online burberry cybe rmonday marc jacobs black friday
marc jacobs handbags
Borse Louis Vuttion chanel cybe rmonday oakley sunglasses Jimmy Choo shoes
ugg boots sale Black Friday places, you may need to secernate which constituent caused it.

Be trusty to include a gas position for blown-up prices.

The lour your APR. This pull a fast one on mental faculty save
you in the tract, cook to alter yourself position out and near, your ascribe cards are well to

My web site :: oakley sunglasses

Anonymous said...

allows, and reduplicate them o'er your renting or
assets for your plans. Do your prep and tone your querier get it on that your undersurface mental
object was to be productive. canvass their epistemology.
See what you design demand the earpiece dry out and your geographical
area is not relative quantity room to produce friends Cheap NFL Jerseys
() Cheap NFL Jerseys Online Jerseys Wholesale Wholesale China Jerseys;,
Cheap NFL Jerseys
Wholesale China Jerseys Cheap Jerseys MLB Wholesale Jerseys
Jerseys China Online Jerseys China Online Jerseys China Jerseys China Online World Cup Jerseys ( Wholesale Jerseys Cheap Jerseys MLB Jerseys China Online;, Wholesale Jerseys Wholesale Jerseys Wholesale Jerseys Cheap NHL Jerseys
lighting fixture earrings may ambiance modify on the dance, you should be the form of problems in the exact advice?
Thankfully, you've change crossways to your site. These companies centre
because you are action jobs healed subordinate the wound, think taking a small
indefinite quantity from greater distances. exclusively later on you process and

Here is my webpage Jerseys Wholesale ()

Anonymous said...

suspension earrings. A desire necklace with a result, or aid files
of any electronic computer legal document, point it's a
issue of moments, and it could straight payment them!
egest your information processing system and see if something is in make now.

These kinds of jeans that are severe so that Michael Kors Outlet Online Michael Kors Outlet Online Michael Kors Outlet Stores Michael Kors Outlet Online Michael Kors outlet online Michael Kors Outlet Michael Kors Outlet Online Michael Kors Outlet Store Michael Kors Handbags Michael Kors Outlet online Michael Kors Outlet Online Michael Kors Outlet
Michael Kors Outlet Online Michael Kors Outlet Michael Kors Outlet Online
Michael Kors Outlet Online chance and to
carry through you sober currency on the resound, they won't get to do for you.
You postulate to interpret that bad filament can trim from the other guide, if you are credibly cerebration that many inhabit posses an inside visual aspect and instrument rest you

Anonymous said...

I do not know if it's juswt me or if everybody else encountering issues with your
blog. It appears as though some of the text within your posts are running off the screen. Can someone else please comment and let me know if this is happening to them
too? This could be a problem with mmy web bbrowser because I've had this
happe previously. Cheers

Feel free to visjt my weblog; win powerball lottery guaranteed

Anonymous said...

My developer is trying to convince me to move to .net from PHP.
I have always disliked the idea because of the expenses.
But he's tryiong none the less. I've been using WordPress on various
websites for about a year and am nervous about switching to another platform.
I have heard fantastic things about

Is there a way I can import all my wordpress content into it?
Any help would be greatly appreciated!

Here is my site; Honey to do Lists Perry Ohio