Specific Characters
As mentioned before, everything that’s not special in a pattern matches itself.
That means an /a/ matches an
“a”, an /=/ matches an “=”, and so on. Some characters, though, aren’t
very easy to type in—and even if you manage that, they’ll just mess up
your screen formatting. (If you’re lucky. Control characters are notorious for being out-of-control.) To fix that,
regexes recognize the double-quotish character aliases listed in Table 5-10.
Table 5-10. Double-quotish character aliases
| Escape | Meaning |
|---|---|
\0 | Null character (nul, null) |
\a | Alarm (bel, alert) |
\e | Escape (esc, escape) |
\f | Form feed (ff, form feed) |
\n | Newline (lf, line feed) |
\r | Return (cr, carriage return) |
\t | Tab (ht, horizontal tab) |
Just as in double-quoted strings, patterns also honor the following five metasymbols:
\cXA named ASCII control character, like
\cCfor Control-C,\cZfor Control-Z,\c[for ESC, and\c?for DEL. The resulting ordinal must be 0–31 or 127.\NNNA character specified using its two- or three-digit octal code. The leading
0is optional, except for values less than010(8 decimal) since (unlike in double-quoted strings) the single-digit versions are always considered to be references to strings captured by that numbered capture group within a pattern. Multiple digits are interpreted as the nth reference if you’ve captured at least n substrings earlier in the pattern (where n is considered as a decimal number). Otherwise, they are interpreted as a character specified in octal.\x{HEXDIGITS}A codepoint (character ...
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