Anchors
Basic metacharacters
Character classes
Comments
Control and code
Grouping
Look around
Mode modifiers
Quantifiers
Specific characters
|
Usually match modes, e.g. whether the match should be case-insensitive or not, are set outside of the regular expression. Mode modifiers allow you to set them inside and for parts of an expression.
Basic structure
Mode modifiers
Basic structure
|
Item
|
|
Meaning:
|
|
|
(?M)
|
|
Turn modifier M on for the rest of the expression or until it is turned off.
|
|
|
(?-M)
|
|
Turn modifier M off for the rest of the expression or until it is turned on.
|
|
|
(?M:…)
|
|
Turn modifier M on for the expression between the non capturing parentheses.
(Note: the modifier is followed by colon.)
|
|
|
In the table “…” stands for any one or more characters.
|
|
Mode modifiers |
|
Item
|
|
Mode:
|
|
|
i
|
|
Case-insensitive mode.
|
|
|
m
|
|
Multiline mode
Allow ^ and $ to match at embedded newlines.
|
|
|
s
|
|
Dot matches all mode.
Dot (. ) will match any character including newline.
|
|
|
x
|
|
Free flow mode.
Ignores (most) whitespace and permits comments preceded by “# ” in an expression.
|
|
|
You can combine multiple modifiers, turning some on and some of. For example (?i-m) will turn case-insensitivity on and multiline mode off.
|