Fortinet Document Library

Version:

Version:

Version:

Version:

Version:

Version:


Table of Contents

Administration Guide

Syntax

The following table lists some example regular expressions, and describes matches for each expression. Regular expressions on FortiMail units use Perl-style syntax.

Regular expression syntax

Expression

Matches

abc

abc (the exact character sequence, but 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 characters, followed by c

ab{2,}c

a followed by at least two “b”s followed by a “c”

ab*c

a followed by any number (zero or more) of “b”s followed by a “c”

ab+c

a followed by one or more b's followed by a c

ab?c

a followed by an optional “b” followed by a” c”; that is, either “abc” or “ac”

a.c

a followed by any single character (not newline) followed by a “c”

a\.c

a.c

[abc]

Any one of a, b or c

[Aa]bc

Either Abc or abc

[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, 12bar8, or foo_1

100\s*mk

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

abc\b

abc when followed by a word boundary (for example, abc! but not abcd)

start\B

start when not followed by a word boundary (for example, starting but not start time)

\x

Ignores white space that is neither preceded by a backslash character nor within a character class. Use this to break up a regular expression into (slightly) more readable parts.

/x

Used to add regular expressions within other text. If the first character in a pattern is forward slash (/), the / is treated as the delimiter. The pattern must contain a second /. The pattern between / will be taken as a regular expression, and anything after the second / will be parsed as a list of regular expression options (i, x, etc). An error occurs If the second / is missing. In regular expressions, the leading and trailing space is treated as part of the regular expression.

Syntax

The following table lists some example regular expressions, and describes matches for each expression. Regular expressions on FortiMail units use Perl-style syntax.

Regular expression syntax

Expression

Matches

abc

abc (the exact character sequence, but 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 characters, followed by c

ab{2,}c

a followed by at least two “b”s followed by a “c”

ab*c

a followed by any number (zero or more) of “b”s followed by a “c”

ab+c

a followed by one or more b's followed by a c

ab?c

a followed by an optional “b” followed by a” c”; that is, either “abc” or “ac”

a.c

a followed by any single character (not newline) followed by a “c”

a\.c

a.c

[abc]

Any one of a, b or c

[Aa]bc

Either Abc or abc

[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, 12bar8, or foo_1

100\s*mk

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

abc\b

abc when followed by a word boundary (for example, abc! but not abcd)

start\B

start when not followed by a word boundary (for example, starting but not start time)

\x

Ignores white space that is neither preceded by a backslash character nor within a character class. Use this to break up a regular expression into (slightly) more readable parts.

/x

Used to add regular expressions within other text. If the first character in a pattern is forward slash (/), the / is treated as the delimiter. The pattern must contain a second /. The pattern between / will be taken as a regular expression, and anything after the second / will be parsed as a list of regular expression options (i, x, etc). An error occurs If the second / is missing. In regular expressions, the leading and trailing space is treated as part of the regular expression.