Well - Before I jump to the applications of regular expressions, Let me explain what regular expressions are.
Definition :
A regular expression is a pattern of characters(meta characters and special characters).
Regular Expressions in QTP :
We can use regular expressions in qtp in many ways as mentioned below.
Set myRegEx = New RegExp
Definition :
A regular expression is a pattern of characters(meta characters and special characters).
General Applications of Regular Expressions :
Where are regular expressions used.
Where are regular expressions used.
- Pattern Matching in Strings
- To find the occurrences of one string/pattern in given string.
- To replace the patterns with another string in a given text
All programming languages support the use of regular expressions.
Regular Expressions in QTP :
We can use regular expressions in qtp in many ways as mentioned below.
- In QTP, object repository is used to store the object's properties and values. We can use regular expressions to specify the object property value.This helps us using same test object to identify multiple run time objects in the application.
- We can also use regular expressions in descriptive programming.
QTP examples on Regular Expressions:
As I said earlier We use regular expressions to check if the given string matches the specified pattern.
For example - Consider a scenario where you have to validate that the given string should be a valid email address.
So list of valid email addresses are - reply2sagar@gmail.com, ayx@jjjj.in etc
Some of the invalid email addresses are - kjkjj@fdff, @dfdf.in etc
With the help of regular expression, you can easily validate the email address.
Syntax of Regular Expression in QTP:
In any QTP program related to regular expression, you will follow below steps.
For example - Consider a scenario where you have to validate that the given string should be a valid email address.
So list of valid email addresses are - reply2sagar@gmail.com, ayx@jjjj.in etc
Some of the invalid email addresses are - kjkjj@fdff, @dfdf.in etc
With the help of regular expression, you can easily validate the email address.
Syntax of Regular Expression in QTP:
In any QTP program related to regular expression, you will follow below steps.
- Create a regular expression object (RegExp)
- Define the pattern using RegExp object's pattern property.
- Use test method to check whether the given string matches with the pattern specified in step 2.
Set myRegEx = New RegExp
'Specify the pattern (Regular Expression)
myRegEx.Pattern = "[a-z0-9]+@[a-z]+\.[a-z]+"
'Specify whether the matching is to be done with case sensitivity on or off.
myRegEx.IgnoreCase = True
'Use Test method to see if the given string is matching with the pattern
isMatched = myRegEx.Test("reply2sagar@gmail.com")
Variable isMatched will be true if the string "reply2sagar@gmail.com" matches with the given pattern
"[a-z0-9]+@[a-z]+\.[a-z]+"
You may also like below topics on regular expressions in QTP.
Please give your inputs, suggestions, feedback to Us about above QTP topic. We value your thoughts.
- Regular Expressions in OR in QTP.
- Regular Expressions in descriptive programming in QTP.
- Regular expression evaluator in QTP.
- Meta characters in regular expressions.
- Case insensitive regular expressions in QTP.
- Regexp object in QTP.
- Global Property in Regular Expressions
Please give your inputs, suggestions, feedback to Us about above QTP topic. We value your thoughts.
No comments:
Post a Comment
Please Leave your reply. We value your feedback and inputs