Regex Modifiers
Explore how to apply various regex modifiers in Perl to control the behavior of pattern matching and substitutions. Understand case-insensitivity, multiline matching, and other options to improve your text processing skills and write clearer, more maintainable regex code.
The /i modifier
Several modifiers change the behavior of the regular expression operators. These modifiers appear at the end of the match, substitution, and qr// operators. For example, here’s how to enable case-insensitive matching:
The first like() will fail because the strings contain different letters. The second like() will pass, because the /i modifier causes the regex to ignore case distinctions. L and l are effectively equivalent in the second regex due to the modifier.
Embedding regex modifiers within patterns
We can also embed regex modifiers within a pattern:
The (?i) syntax enables case-insensitive matching only for its ...