Fortinet white logo
Fortinet white logo

Administration Guide

Syntax

Syntax

Regular expressions on FortiMail units use Perl-style syntax. The following table lists some example regular expression syntax, and describes strings that match and do not match.

Regular Expression

Matches and Non-Matches

abc

abc anywhere in the string.

^abc

abc at the beginning of the string.

abc$

abc at the end of the string.

a|b

Either a or b.

^abc|abc$

abc at either the beginning or the end of the string.

ab{2,4}c

a followed by two, three, or four b and then c.

ab{2,}c

a followed by at least two b and then c.

a.*c

a followed by zero or more characters of any type, and then c.

ab+c

a followed by one or more b and then c.

ab?c

a followed by an optional b and then c. That is, either abc or ac.

a.c

a followed by any single character (not newline) and then c.

a\.c

a.c

Note

Backslash is an escape character.You can use it to match any character such as * or . literally, not interpret it as a wildcard operator in pattern syntax.

[abc]

Either a, b, or c.

[Aa]bc

Either Abc or abc.

[A-Za-z]

Match any single uppercase or lowercase letter in the English language alphabet, but not numbers or special characters.

[abc]+

Any combination of one or more a, b, and/or c characters, such as a, abba, or acbabcacaa.

[^abc]+

Any combination of one or more characters that does not contain an a, b, and/or c, such as defg.

\d\d

Any two decimal digits, such as 42. Same as \d{2}.

\w+

A word (a non-empty sequence of alphanumeric characters and underscores), such as foo, bar8, or baz_1.

100\s*mk

100 and mk separated by zero or more white space characters (spaces, tabs, newlines).

abc\b

abc followed by a word boundary, such as abc! but not abcd.

start\B

start when not followed by a word boundary, such as starting but not start time.

\x{2709}

The character or emoji 2709 (an envelope icon), defined by its Unicode hexadecimal character number.

/a b c/x

abc anywhere in the string.

Note

Delimiters can be used to add regular expressions within other text.

Delimiters surround the regular expression. The first character (in this example, /) is used as the delimiter. Between the first and second delimiter is the regular expression pattern. Leading and trailing space, if any, is treated as part of the regular expression. If the second / is missing, an error occurs.

Anything after the second / are options. In this example, the option x ignores white space between the letters in the pattern a b c.

Syntax

Syntax

Regular expressions on FortiMail units use Perl-style syntax. The following table lists some example regular expression syntax, and describes strings that match and do not match.

Regular Expression

Matches and Non-Matches

abc

abc anywhere in the string.

^abc

abc at the beginning of the string.

abc$

abc at the end of the string.

a|b

Either a or b.

^abc|abc$

abc at either the beginning or the end of the string.

ab{2,4}c

a followed by two, three, or four b and then c.

ab{2,}c

a followed by at least two b and then c.

a.*c

a followed by zero or more characters of any type, and then c.

ab+c

a followed by one or more b and then c.

ab?c

a followed by an optional b and then c. That is, either abc or ac.

a.c

a followed by any single character (not newline) and then c.

a\.c

a.c

Note

Backslash is an escape character.You can use it to match any character such as * or . literally, not interpret it as a wildcard operator in pattern syntax.

[abc]

Either a, b, or c.

[Aa]bc

Either Abc or abc.

[A-Za-z]

Match any single uppercase or lowercase letter in the English language alphabet, but not numbers or special characters.

[abc]+

Any combination of one or more a, b, and/or c characters, such as a, abba, or acbabcacaa.

[^abc]+

Any combination of one or more characters that does not contain an a, b, and/or c, such as defg.

\d\d

Any two decimal digits, such as 42. Same as \d{2}.

\w+

A word (a non-empty sequence of alphanumeric characters and underscores), such as foo, bar8, or baz_1.

100\s*mk

100 and mk separated by zero or more white space characters (spaces, tabs, newlines).

abc\b

abc followed by a word boundary, such as abc! but not abcd.

start\B

start when not followed by a word boundary, such as starting but not start time.

\x{2709}

The character or emoji 2709 (an envelope icon), defined by its Unicode hexadecimal character number.

/a b c/x

abc anywhere in the string.

Note

Delimiters can be used to add regular expressions within other text.

Delimiters surround the regular expression. The first character (in this example, /) is used as the delimiter. Between the first and second delimiter is the regular expression pattern. Leading and trailing space, if any, is treated as part of the regular expression. If the second / is missing, an error occurs.

Anything after the second / are options. In this example, the option x ignores white space between the letters in the pattern a b c.