Regular expression syntax

The regular expression engine in QA Distiller uses the Perl Compatible Regular Expressions library. This topic covers the basics of regular expressions. It is designed as a short reference guide for users who wish to write advanced regular expressions. QA Distiller warns you when you have entered an invalid expression.

Single characters

Any single character matches itself, unless it is a metacharacter with a special meaning (described below). For example, the pattern "test" matches the literal string "test''.

Escape sequences

Some characters can be specified using an escape sequence syntax.

The most common escape sequences are:
  • \t represents a tab
  • \n represents a new line
  • \r represents a carriage return

Character classes

You can define a character class by specifying a range of characters, like [a-z], or by listing the targeted characters individually [abcde]. You can exclude some characters from the range: if the first character after the "['' is "^'', the class matches any character, except the characters that follow the ^ symbol.

Examples:
  • [a-z] matches any character between 'a' and 'z'

  • [^aeiou] matches any character except the vowels a, e, i, o and u

Metacharacters

Metacharacters are special characters that are the essence of regular expressions. There are different types of metacharacters:
  • Line separators:
    Character Description
    ^ Start of a line
    $ End of a line
    \A Start of text
    \Z End of text
    . Any character in line
  • Predefined classes:
    Character Description
    \w Any alphanumeric character
    \d Any digit
    \s Any space
  • Iterators:
    Any item of a regular expression can be followed by an iterator. Metacharacters can specify a number of occurrences.
    Character Description
    * This is the same as {0,}
    + One or more, this is the same as {0,}
    ? Zero or one, this is the same as {0,}
    {n} Exactly n times
    {n,} At least n times
    {n,m} At least n but no more than m times
  • Alternatives:

    You can specify alternatives for a pattern using the pipe character "|'' to separate the alternatives.

    Example: a|b means a or b

  • Grouping:

    Round brackets are used to group several characters inside a regular expression.

    Example:
    • I like (dogs|cats) matches both ”I like dogs” and ”I like cats”.

    • ([A-Z]\d)+ matches a sequence of one or more letter-digit combinations.

The following string represents a model number: AA\{2}
  • AA represents the literal string
  • \d{2} represents exactly 2 digits

According to the above regular expression, valid examples of this model number can be: AA01, AA25, AA99