The Default Behavior For Matching Can Be Changed
The Default Behavior For Matching Can Be Changed
Modifiers that
relate to the interpretation of the pattern are listed just below. Modifiers that alter the way a
pattern is used by Perl are detailed in "Regexp Quote-Like Operators" in perlop and "Gory
details of parsing quoted constructs" in perlop. Modifiers can be added dynamically;
see "Extended Patterns" below.
Treat the string being matched against as multiple lines. That is,
change "^" and "$" from matching the start of the string's first line and the end of its
last line to matching the start and end of each line within the string.
Treat the string as single line. That is, change "." to match any character
whatsoever, even a newline, which normally it would not match.
Used together, as /ms, they let the "." match any character whatsoever, while still
allowing "^" and "$" to match, respectively, just after and just before newlines within
the string.
Do case-insensitive pattern matching. For example, "A" will match "a" under /i.
If locale matching rules are in effect, the case map is taken from the current locale for
code points less than 255, and from Unicode rules for larger code points. However,
matches that would cross the Unicode rules/non-Unicode rules boundary (ords
255/256) will not succeed, unless the locale is a UTF-8 one. See perllocale.
# The below doesn't match, and it isn't clear what $1 and $2 would
# be even if it did!!
Perl doesn't match multiple characters in a bracketed character class unless the
character that maps to them is explicitly mentioned, and it doesn't match them at all if
the character class is inverted, which otherwise could be highly confusing.
See "Bracketed Character Classes" in perlrecharclass, and "Negation" in
perlrecharclass.
x and xx
Extend your pattern's legibility by permitting whitespace and comments. Details in "/x
and /xx"
a, d, l, and u
These modifiers, all new in 5.14, affect which character-set rules (Unicode, etc.) are
used, as described below in "Character set modifiers".
Prevent the grouping metacharacters () from capturing. This modifier, new in 5.22,
will stop $1, $2, etc... from being filled in.
# "hello"
Other Modifiers
There are a number of flags that can be found at the end of regular expression
constructs that are not generic regular expression flags, but apply to the operation
being performed, like matching or substitution (m// or s/// respectively).
/x and /xx
/[d-eg-i3-7]/
/[!@"#$%^&*()=?<>']/
$program =~ s {
} []gsx;
U+0020 SPACE