Real meaning of Regular Expression’s(RG’s) – User friendly Tech help
n
It is a way of representing data using symbols, which are in the form of special characters like ‘*’,’ +’, ’.’, ’’.
n
n Further these characters are used for search of particular pattern in strings.
n
RG’s in UFT:
n
These are used in UFT to identify objects and text strings with varying values very useful in dynamic objects.
n
Usage:
n1. Defining Properties of an Object. (Object Repository)n
2. Pattern matching in Check points.
n
3. Parameterize an object property or check point
n
Test:
n
We can test pattern match using “Regular Expression Evaluator”
n
Tools>Regular Expression Evaluator.
Screenshot of window: RG evaluator
n
Using RG in UFT:
n
n1. 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.n
2. 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.
n
3.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,
n4.For XML checkpoints we can set attribute or element values as regular expressions.
n
Types of RG’s:
n
i) Backslash Character:
n
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.
nFor example, UFT recognizes n as the special newline character. n
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.
n
For example, w matches the character w
nw is a special character that matches any word character including underscore.
n
Practical example:-
n
In the URL of a blog http://uftautomation.blogspot.in/,
nThe period would be mistaken as an indication of a regular expression. To indicate that the
nperiod is not part of a regular expression, you would enter it as follows:
nuftautomation.blogspot .inn
ii) Matching Any Single Character:
n
A period (.) tells UFT to search for any single character (except for n).
nFor example:
n
RG:Train.
nMatches Trains, Trained, or Train followed by a space or any other single character.
n
iii) Matching Any Single Character in a List:
n
nSquare brackets [] instruct UFT to search for any single character within a list of characters.
nFor example:n
To search for the Year 2013, 2019, or 2015,
n
RG: 201[359]
n
iv) Matching Any Single Character Not in a List:
n
n When a caret (^) is the first character inside square brackets, it instructs UFT to match
n any character in the list except for the ones specified in the string.
nFor example:
nRG: [^13]
nMatches any character except 1 or 3.
n
v) Matching Any Single Character within a Range:
n
n To match a single character within a range, we can use square brackets ([ ]) with the
nhyphen (–) character.
nFor example: For matching any number in the range 1000s,n
RG: 100[0-9]
n n
Screenshot: We are looking for 3 digit number between (130 -149)
n
RG: [1][3-4][0-9]
vi) Matching Zero or More Specific Characters:
n
n An asterisk (*) instructs UFT to match zero or more occurrences of the preceding
n
For example:
n
RG: ma*n
nMatches man, maaaaaan, and ma
n
vii) Matching One or More Specific Characters:
n
n A plus sign (+) instructs UFT to match one or more occurrences of the preceding
ncharacter.
nFor example:
nRG: ma+n
nMatches man and maaaaaaan, but not mn.
n
viii) Matching Zero or One Specific Character:
n
nA question mark (?) instructs UFT to match zero or one occurrences of the preceding
ncharacter.
nFor example:
nRG: ma?n
nMatches man and ma , but nothing else.
n
ix) Grouping RG:
n
n Parentheses (()) instruct UFT to treat the contained sequence as a unit, just as in
nmathematics and programming languages. Using groups is especially useful for delimiting
n the argument(s) to an alternation operator ( | ) or a repetition operator ( * , + , ? , { } ).
n
x) Matching One of Several RG’s:
n
n A vertical line (|) instructs UFT to match one of a choice of expressions.
n
xi) Matching the Beginning of a input:
n
n A caret (^) instructs UFT to match the expression only at the start of a line, or after
n a newline character.n
xii) Matches the end of input:
n
A dollar sign ($) instructs UFT to match the expression only at the end of a line, or before a newline character.
n
xiii) Matching Any Alphanumeric Character Including the Underscore:
n
n w instructs UFT to match any alphanumeric character and the underscore any combination
n of (A-Z, a-z, 0-9, _).
n
xiv) Matching Any Non-Alphanumeric Character:
n
n W instructs UFT to match any character other than alphanumeric characters and
nunderscores any combination other than (A-Z, a-z, 0-9, _).
n
Some other cardinal RG’s:
n
a) Matches a digit character : d, it is Equivalent to [0-9].
n
b) Matches a non-digit character: D, it is Equivalent to [^0-9].
n
c) Matches a newline character: n
nd) Matches a carriage return character: r
ne) Matches a tab character: t