Use .NET compatible regular expressions

A regular expression is a character string that consists of characters and metacharacters. You can use regular expressions to find character patterns in a text. For instance, regular expressions can help you find data that can be expressed in different formats, such as: Dates (e.g. mm/dd/yy, dd-mm-yyyy).

For further information on regular expressions, see Microsoft .NET Documentation: Regular Expression Language - Quick Reference.

You can add regular expressions when you configure your OSV Scenarios in Tosca Commander. To do so, enter your regular expressions as values as described in chapter "Configure OSV Scenarios". You can use regular expressions with the ActionModes WaitOn and Verify.

Use metacharacters

Metacharacters are characters with a special meaning. You can use the following metacharacters in regular expressions:

Character

Description

Examples

[ ]

Finds every character in the square brackets.

You can group several characters.

[abc] matches a, b or c.

[a-z] defines the range of lowercase letters from a to z.

[^]

Finds every character that is not in the square brackets.

You can group characters and use ranges.

[^abc] matches every character except a, b or c.

[^a-z] matches every character except lowercase letters from a to z.

.

Matches any single character except for a line or paragraph break.

a.c matches abc, aTc, a$c, a c etc.

\d

Finds numeric characters.

\d\d\d matches any three digit number, e.g. 145, 238 etc.

\w

Finds alphanumeric characters.

\w matches a, b, c, d, e, f in abc def.

+

Specifies that the preceding element appears one or more times.

ab+c matches abc, abbc, abbbc etc.

?

Specifies that the preceding element appears once or not at all.

ab?c matches ac or abc.

*

Specifies that the preceding element appears zero or more times.

ab*c matches ac, abc, abbc etc.

{n}

Specifies that the preceding element appears exactly n times.

ab{3}c matches abbbc.

{n,m}

Specifies that the preceding element can appear at least n times but not more than m times.

ab{2,4}c matches abbc, abbbc and abbbbc.

\b

Finds a word boundary.

\b\d\d\w+ matches a character string that begins with two numbers and continues with one or more alphanumeric characters, e.g. 12He(\t34aq.

( )

Defines sub-expressions.

(\d\d\d\s)+ matches sequences of three-digit numbers, e.g. 123 456 789 012.

|

Finds either the preceding or following element.

(ab)|(cd) matches ab or cd.

\

Specifies if the following character has a literal or special meaning.

\+ indicates the plus sign, + is a metacharacter.

\d is a metacharacter, d indicates the respective letter of the alphabet.

^

Indicates the beginning of a line.

^The matches any string that begins with The.

$

Indicates the end of a line.

$end matches any string that ends with end.

\s

Finds whitespace characters.

\s* matches zero or more whitespace characters.

i

Uses case-insensitive matching.

(?i)test ignores upper-case and lower-case to find a match, e.g. test, Test, TEST, teST etc.

Examples of regular expressions

Example 1: Date

In this example, you use a regular expression to find dates.

Syntax:

{REGEX["^\d{1,2}[ /.-]\d{1,2}[ /.-](\d{4}|\d{2})$"]}

In this example, you use the expression {REGEX["^\d{1,2}[ /.-]\d{1,2}[ /.-](\d{4}|\d{2})$"]} to search for dates in various possible formats.

The pattern includes:

  • ^: beginning of the line

  • \d{1,2}: day (one or two digits long)

  • [ /.-]: separators (space, forward slash, dot or hyphen)

  • \d{1,2}: month (one or two digits)

  • [ /.-]: separators (space, forward slash, dot or hyphen)

  • (\d{4}|\d{2}): year (two or four digits)

  • $: end of line

Regular expression in the Value field

The possible search results include: 9/3, 12.12.87, 1-1-1999, 11.1986, 04/23/2007, 01.03.2000, 4.8

Example 2: ISO8601 date and time

In this example, you use a regular expression to find the combination date and time in a specific format.

Syntax:

{REGEX["^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z$"]}

In this example, you use a regular expression to search for date and time in ISO8601 format, i.e. the international standard for the exchange of date- and time-related data.

Using the expression {REGEX["^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z$"]}, you search for combined date and time in Coordinated Universal Time (UTC).

The pattern includes:

  • ^: beginning of line

  • \d{4}: year (four digits)

  • -: separator (hyphen)

  • \d{2}: month (two digits)

  • -: separator (hyphen)

  • \d{2}: day (two digits)

  • T: delimiter between date and time

  • \d{2}: exactly two digits

  • :: separator (colon)

  • \d{2}: hour (two digits)

  • :: separator (colon)

  • \d{2}: second (two digits)

  • Z: time zone designator (UTC)

  • $: end of line

Regular expression in the Value field

The possible search results include: 2013-10-03T12:00:00Z, 1776-07-04T13:37:11Z, 1993-01-01T00:00:00Z

Example 3: Telephone numbers

In this example, you use a regular expression to find telephone numbers.

Syntax:

{REGEX["(((00|\+)(420|43))|0)\s?\d+/?(\s?\d)+"]}

In this example, you use the regular expression {REGEX["(((00|\+)(420|43))|0)\s?\d+/?(\s?\d)+"]} to search for telephone numbers in various possible formats.

The pattern includes:

  • (((00|\+)(420|43))|0): finds 00420, 0043, +420, +43 or 0

  • \s?: possible space

  • \d+: one or more digits

  • /?: possible forward slash

  • (\s?\d)+: string of digits with possible whitespace in between

Regular expression in the Value field

The possible search results include: +43664 1234567, 0699 1234 5678 9, 00420669/1 23 456 7