How to control the overal mode of a regular expression.
Modes
This page describes how to control the overal mode of a regular expression.
N.B. - All of the modes operate relative to a specific group. For details of options see the page on Groups. The default scope for mode specifiers is the, entire regular expression. The mode change takes place at the beginning the group no matter where the mode specifier is placed within the group. This remains true for the root group, i.e. the group for which there is no parenthesis. Other options are available.
Character
Description
Example
Ways to specify the expression mode
(?i)
Enable case insensitivity.
te(?i)st
matches
test
and
TEST
.
(?-i)
Disable case insensitivity.
te(?-i)st
matches
test
but not
TEST
.
(?s)
Enable "dot matches newline".
(?-s)
Disable "dot matches newline".
(?m)
Enable "dollar and caret on line ends".
(?-m)
Disabel "dollar and caret on line ends".
(?i-sm)
Mode specifiers can be concatenated, this enables "i" and disables "s" and "m".
(?i-sm:expn-text)
Modes can be localised, in this case the expression text is parsed with "i" enabled and "s" and "m" disabled. The parent of this group would operate in the default mode, or whichever mode had otherwis been specified for it previously.