Explanation of Regular Expressions

In the following examples for regular expressions, the text in the left column is validated against the regular expression in the right column. The text marked in bold is matched by the regular expression.

Table 1. Matching letters

Text

RegEx

abc

def

abc

abc

de

Abc

d

With letters, you can search anywhere inside a text for matches.

Table 2. Matching digits

Text

RegEx

number = 123

123 or \d\d\d

var number =

123

ab123fg

Digits have the same effect as letters. Instead of a specific digit, you can use the character class “\d” to match any digit.

Table 3. Matching any character

Text

RegEx

bob.

…\.

tom.
?!a.

abc1

“.” matches any character. If you want to match a dot, escape it with “\.”.

Table 4. Matching multiple characters

Text

RegEx

aaaaaaaaaaab

b+

aabbbbbc

acd

aaaaaabbe

The trailing plus sign means that the sign may occur once or several times. If it does not occur, there is no match.

Table 5. Optional characters

Text

RegEx

3 users online

\d+ users? online

150 users online
20 users online
1 user online

no user online

By appending a “?”, the leading character is declared as optional.

Table 6. Grouping regular expressions

Text

RegEx

dump025.csv

\w+\d+\.(\w+)

dump026.csv

Parentheses around a part of the regular expression group the enclosed elements. In the example above, the file extension after the dot is a group.

Important:

You can only create one group per regular expression.

Table 7. Matching either/or

Text

RegEx

data.csv

.*\.(exe|xlsx)

bild.jpg

moving.gif

document.pdf

virus.exe
locky.xlsx

The “|” inside the parentheses describes that any pattern separated by it is valid.

Table 8. Backreferencing

Text

RegEx

From: "local@domain.de" <local@domain.de>

From: "(.*@.*\.de)" \<\1\>

From: "local@domain.de" <hacker@hackeddomain.de>

The backreference \1 stands for the group definition (.*@.*\.de). A match is only made if the match of the group appears again at the referenced place.

The following syntax elements can be used to define regular expressions in the Compliance Filter:

Table 9. Syntax elements

Wildcard/Character class

Function

abc…

Letters

123…

Digits

\d

Any digit

.

Any character

\. \/ \

*

Escaping the characters in bold

\w

Any alphanumeric character

*

0 or more repetitions

+

1 or more repetitions

?

Optional character

\s

Any whitespace

(…)

Extraction group

(.*)

All

(abc|def)

abc or def