You're here: Reference > Regular Expressions

previous topic  next topic

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 Stingray Application Firewall.

Important: Stingray Application Firewall 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 Stingray Application Firewall. We strongly recommend to use only the syntax elements that are described below.

Caution: 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.

Expand /Collapse All Subsections

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

Syntax

Meaning

E?

The element E is optional.

E*

The element E can occur any number of times, or be left out.

E+

The element E can occur any number of times, but must occur at least once.

*?

+?

??

The qualifiers ?, * and + are all “greedy”, which means that they match as much text as possible. This behavior isn’t always what you want.

Example: The regular expression <.*> observes both <H1>Title</H1> and <H1>, for example.

A ? after the qualifier restricts the match to a minimum number of characters.

Example: <.*?> only match <H1> and not <H1>Title</H1>.

E{n,m}

The element E occurs at least n times, but a maximum of m times.

E1|E2

Either element E1 or element E2 occurs.

(E1E2)

Combines elements E1 and E2 into a new element (group).

Important:  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 Stingray Application Firewall.

Examples

Regular expression

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

©  Riverbed Technology, all rights reserved   previous topic  next topic