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 ...
Get Perl Pocket Reference, 5th Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.