Regular Expression Patterns
The operator qr can be used to create patterns.
- qr /pattern/ [ modifiers ]
Creates a pattern.
Patterns can also be created implicitly when using search and replace functions.
Modifiers can be used as indicated, but also inside of the pattern using {?modifiers). In this case, modifiers imsx can be switched on and off.
| searches in a case-insensitive manner. |
| multiline mode: |
| interpolates variables only once. |
| preserves |
| single-line mode: |
| allows for whitespace and comments. |
| in |
These modifiers are mutually exclusive:
| forces strict ASCII matching, repeat for stricter ASCII matching. |
| semantics depend on other settings. |
| treats the pattern with locale properties. |
| treats the pattern with full Unicode semantics. |
perlre, perlretut, perlrequick, perlunicode.
The elements that form the pattern are based on regular expressions, but nowadays contain many nonregular extensions.
Basically each character matches itself, unless it is one of the special characters +?.*^$()[{|\. The special meaning of these characters can be escaped using a \.
.Matches any character, but not a newline. In single-line mode, matches newlines as well.
( . . . )Groups a series of pattern elements to a single element. The text the group ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access