Pattern-matching modifiers

The regular expression syntax has Perl-like extensions. The pattern-matching modifiers are extensions that can be used to control the matching process in more detail.

The modifiers are enabled with (?<modifiers>) and disabled with a minus (?-<modifiers>), where <modifiers> is a list of one or more modifiers.

Example of pattern-matching modifiers

# This fingerprint is identical to the special character sequence example,
# except for the (?i) modifier.
# HTTP Header names are case-insensitive. For this reason,
# case-insensitivity is enabled in this fingerprint.
(?i)Content-Length: \d\d\d\d\d

The modifiers (?C), (?L), and (?s)are enabled by default.

The pattern-matching modifiers are listed in the following table:

Table 1. Pattern-matching modifiers
Sequence Description
(?i)

Case insensitive mode

When enabled, case insensitive matching is used for the uppercase and lowercase letters. Thus, a letter matches regardless of its capitalization.

When disabled, the letters are matched case-sensitively so that capitalization is taken into account in the matching process.

(?s)

Single line mode

When enabled, the dot character "." matches also the null character \x00 and a missing character in addition to matching any character (including linefeed and other non-printable characters).

When disabled, the linefeed or a missing character are not matched.

This modifier is enabled by default. Use (?-s) to disable it.

(?x)

Extended readability mode

When enabled, equals to enabling (?C), (?L), and (?S). Comments, linefeeds and spaces are not used in the matching process, allowing to use them for readability of the expression.

When disabled, equals to disabling (?C), (?L), and (?S). Comments, linefeeds, and spaces are used in the matching process.

(?C)

Allow comments mode

When enabled, anything after the hash character "# " is regarded as a comment and not included in the matching process.

When disabled, the hash character "# " and anything following are used in the matching process.

This modifier is enabled by default. Use (?-C) to disable it.

(?L)

Ignore linefeeds mode

When enabled, linefeed and carriage return characters are not included in the matching process unless defined (\x0A or \n for linefeed and \x0D or \r for carriage return).

When disabled, linefeeds and carriage returns are used in the matching process.

This modifier is enabled by default. Use (?-L) to disable it.

(?S)

Ignore spaces mode

When enabled, the space and horizontal tab characters are not used in the matching process unless defined (\x20 for space and \x09 or \t for horizontal tab).

When disabled, the space and horizontal tab characters are used in the matching process.

(?<modifiers>:<expr>)

Applies the <modifiers> modifiers only to the expression <expr>.

These modifiers are not used in other parts of the regular expression.