Regular expressions
Tosca TBox supports regular expressions, which are used to compare whether the target attribute contains a string that matches the regular expression. The regular expression must be specified within double quotation marks.
The .NET Framework syntax is used for regular expressions in Tosca TBox.
Syntax: |
{REGEX["regular expression"]} A leading escape character is required in order to allow quotation marks to be used accordingly in the regular expression. |
The start page of an application contains a link which should be steered. This link does not have a unique ID and can be displayed as a German or English text (DE or EN). A regular expression can be specified for the Caption parameter on the Module level, in order to facilitate the search for the page in both languages: {REGEX["^TOSCA HTML"]}.
Regular expression on the Module level A regular expression can be specified for the Id parameter on the Module level in order to click on the link, independent of the currently enabled language: {REGEX["SpracheTabelle|LanguageTable"]}
Regular expression on the ModuleAttribute level |
Random numbers and regular expressions
Random text is specified by using regular expressions. The regular expression must be specified using double quotation marks.
Syntax: |
{RANDOMREGEX["<Regular expression>"]} |
{RANDOMREGEX["^[A-Z][a-z]+[0-9]{4}$"]} A value starting with a capital letter from A-Z is generated, followed by any number of lower case letters and exactly four digits between 0-9. The ^ character denotes the beginning of the line, and the $ character the end of the line. The generated expression is for instance: Ecqwp1989. |
Regular expressions and buffers
Please note that buffers and regular expressions can only be used if the buffer is part of the regular expression:
Syntax: |
{REGEX["Regular expression"{B[BufferName]}"Regular expression"]} |
{REGEX[{B[B_12345]} "(iteration [0-9]{4})"]} This expression can for instance be used to verify the following string: E610Overviewprocess (iteration 0012). In this example, it is assumed that the value E610Overviewprocess was written to the buffer B_12345 beforehand. |
For further examples of regular expressions, please see also chapter "Manage scan results"
Extracting text using regular expressions
You can use regular expressions to verify and extract dynamic parts of a string. Tosca saves these values to buffers for later use.
Named groups specify the name of the buffer and the required pattern of the value.
Use the ActionMode Verify.
Syntax: |
{REGEX["expression(?<buffer name>subexpression)expression"]} Expression: any regular expression specifying the static parts. Buffer name: this is the name for the buffer to which the dynamic part of the comparison is saved. Subexpression: this defines the dynamic part which should be buffered. |
The part (?<buffer name>subexpression) is called named group.
Be aware that the buffer name of a named group has to contain at least one word character.
In this example, Tosca extracts the username from the userinfo label. In the application, the label shows a word as welcome message and the username, followed by an exclamation point. A few possible examples are:
The expression in userinfo verifies if the text in this label matches the pattern and stores the username to the username buffer: {Regex["[a-z]* (?<username>[a-z|\d]*)!"]} The pattern includes:
Buffering parts of a text |