正文

Regular Expression Evaluator

(2011-06-28 06:23:10) 下一個

Regular Expressions

Overview
QuickTest enables you to configure the values for properties and other items by defining a value as a constant or a parameter. You can also use regular expressions for some values to increase the flexibility and adaptability of your tests.
A regular expression is a string that specifies a complex search phrase by using special characters.Regular expressions are used to identify objects and text strings with varying values.
You can use regular expressions only for values of type string.

Regular Expressions for Property Values

If you expect the value of an object property in your application to change in a predictable way during each run session, you can use regular expressions when defining identification property values, for example, in the Object Repository window, or in programmatic descriptions.

Regular Expressions in Checkpoints
you 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.


Regular Expression Characters and Usage Options
By default, QuickTest treats all characters in a regular expression literally, except for the period (.), hyphen (-), asterisk (*), caret (^), brackets ([ ]), parentheses (()), dollar sign ($), vertical line (|), plus sign (+), question mark (?), and backslash (). When one of these special characters is preceded by a backslash (), QuickTest treats it as a literal character.


Using the 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. For example, . would be treated as period (.) instead of a wildcard.
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. For example, n stands for the newline character. If the backslash character is not used for either of these purposes, it is ignored.

Matching Any Single Character ( . )
A period (.) instructs QuickTest to search for any single character (except for n). For example:

welcome.
matches welcomes, welcomed, or welcome followed by a space or any other single character. A series of periods indicates the same number of unspecified characters.


Matching Any Single Character in a List ( [xy] )
Square brackets instruct QuickTest to search for any single character within a list of characters. For example, to search for the date 1967, 1968, or 1969,
enter: 196[789]
Matching Any Single Character Not in a List ( [^xy] )
When a caret (^) is the first character inside square brackets, it instructs QuickTest to match any character in the list except for the ones specified in the string. For example:
[^ab] matches any character except a or b

Matching Any Single Character in a List ( [xy] )
Square brackets instruct QuickTest to search for any single character within a list of characters. For example, to search for the date 1967, 1968, or 1969,
enter: 196[789]

Matching Any Single Character Not in a List ( [^xy] )
When a caret (^) is the first character inside square brackets, it instructs QuickTest to match any character in the list except for the ones specified in the string. For example:
[^ab] matches any character except a or b

Within brackets, the characters ".", "*", "[" and "" are literal.

Matching Zero or More Specific Characters ( * )
An asterisk (*) instructs QuickTest to match zero or more occurrences of the preceding character. For example: ca*r: matches car, caaaaaar, and cr

Matching One or More Specific Characters ( + )
A plus sign (+) instructs QuickTest to match one or more occurrences of the preceding character. For example: ca+r: matches car and caaaaaar, but not cr

Matching Zero or One Specific Character ( ? )
A question mark (?) instructs QuickTest to match zero or one occurrences of the preceding character. For example: ca?r: matches car and cr, but nothing else


Grouping Regular Expressions ( ( ) )
Parentheses (()) instruct QuickTest to treat the contained sequence as a unit, just as in mathematics and programming languages.

Matching One of Several Regular Expressions ( | )
A vertical line (|) instructs QuickTest to match one of a choice of expressions. For example: foo|bar: causes QuickTest to match either foo or bar

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

^book: matches book only in the lines—book and book list

Matching the End of a Line ( $ )
A dollar sign ($) instructs QuickTest to match the expression only at the end of a line, or before a newline character. For example:book$: matches book only in the line—my book

Matching Any AlphaNumeric Character Including the Underscore ( w )
w instructs QuickTest to match any alphanumeric character and the underscore (A-Z, a-z, 0-9, _).

Matching Any Non-AlphaNumeric Character ( W )
W instructs QuickTest to match any character other than alphanumeric characters and underscores. For example: W: matches &, *, ^, %, $, and #


Combining Regular Expression Operators
To match any number between 0 and 1200, you 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.
([0-9]?[0-9]?[0-9]|1[01][0-9][0-9]|1200)


Regular Expression Evaluator
This dialog box enables you to create and test a regular expression to determine whether it suits your needs. You can enter a regular expression and sample text to test. When you click Highlight, QuickTest searches the sample text for matches, highlights these matches, and displays the number of matches.

Smart Regular Expression List
This list:
Displays a list of commonly used regular expression characters.
Enables you to select a regular expression character from the list and insert it in a value.

Tasks:

How to Configure Constant and Parameter Values
click the parameterization button for a selected value and define the value.

[ 打印 ]
閱讀 ()評論 (0)
評論
目前還沒有任何評論
登錄後才可評論.