Regular Expressions

Many settings allow you to use regular expressions for describing specific strings. Given below is an overview of the syntax elements that are supported by vWAF.

vWAF uses the Python regular expressions engine, which is PCRE compatible (Perl compatible). However, the supported syntax is subject to limitations. We don’t guarantee that all features that are supported by the Python regular expressions engine are also supported by vWAF. We strongly recommend to use only the syntax elements that are described below.

ATTENTION
If your regular expressions don’t work as intended, this may result in the loss of protection for your web applications.

A regular expression consists of multiple basic elements. These basic elements can be grouped and repeated in different ways.

Basic elements

Element Meaning

Character Example: A

Letters, numerals, and many special characters stand for themselves. You can type Unicode characters directly as characters. Alternatively you can specify a 2-byte hex value in combination with the prefix \u. Example: \u00e4 represents the German umlaut ä.

\

Special characters that are used as part of the regular expression syntax must be quoted with a backslash. For example, if you mean an actual full stop, you must specify \. because the dot is part of the regular expression syntax (the dot is a placeholder for "any character").

.

Stands for any character.

List of characters in brackets Example: [xyz]

Stands for any one of the included characters (in the example x, y, or z).

Range of characters in brackets Example: [a-d]

Stands for any character within the given range (in the example a, b, c, or d).

\w

Stands for any character or numeral ("word character").

^

Matches the start of the input.

$

Matches the end of the input.

Repeating and grouping

Element Meaning

Character Example: A

Letters, numerals, and many special characters stand for themselves. You can type Unicode characters directly as characters. Alternatively you can specify a 2-byte hex value in combination with the prefix \u. Example: \u00e4 represents the German umlaut ä.

\

Special characters that are used as part of the regular expression syntax must be quoted with a backslash. For example, if you mean an actual full stop, you must specify \. because the dot is part of the regular expression syntax (the dot is a placeholder for "any character").

.

Stands for any character.

List of characters in brackets Example: [xyz]

Stands for any one of the included characters (in the example x, y, or z).

Range of characters in brackets Example: [a-d]

Stands for any character within the given range (in the example a, b, c, or d).

\w

Stands for any character or numeral ("word character").

^

Matches the start of the input.

$

Matches the end of the input.

Back references, such as (a*b)\1 are not supported, even if they sometimes work. If you use back references, we don’t guarantee that your regular expressions will be compatible also with future versions of vWAF.

Examples

Element Meaning

^$

Empty string (no characters).

^.*$

Every string (each character, repeated any number of times).

^(/\w+)+$

Slash / followed by a letter or numeral. This expression is repeated as often as possible, but at least once.

Example: /usr/local/bin

^.{0,32}$

Any string with a maximum length of 32 characters.

^.*\.(html|gif|jpg)$

Any string that ends with .html, .gif or .jpg .

Example: /index.html