Metasymbol Tables
In the following tables, the Atomic column says “yes” if the given
metasymbol is quantifiable (if it can match something with width, more
or less). Also, we’ve used “...” to
represent “something else”. (Please see the later discussion to find out
what “...” means, if it is not clear
from the one-line gloss in the table.)
Table 5-6 shows the basic traditional
metasymbols. The first four of these are the structural metasymbols we
mentioned earlier, while the last three are simple metacharacters. The
. metacharacter is an example of an
atom because it matches something with width (the width of a character,
in this case); ^ and $ are examples of assertions, because they match something of zero width,
and because they are only evaluated to see whether they’re true.
Table 5-6. General regex metacharacters
| Symbol | Atomic | Meaning |
|---|---|---|
\... | Varies | (De)meta next (non)alphanumeric
character alphanumeric character (maybe) |
...|... | No | Alternation (match one or the other) |
(...) | Yes | Grouping (treat as a unit) |
[...] | Yes | Character class (match one character from a set) |
^ | No | True at beginning of string (or after any newline, maybe) |
. | Yes | Match one character (except newline, normally) |
$ | No | True at end of string (or before any newline, maybe) |
The quantifiers, which are further described in their own section, indicate how many times the preceding atom (that is, single character or grouping) should match. These are listed in Table 5-7.
Table 5-7. Regex quantifiers
| Maximal | Minimal | Possessive | Allowed Range |
|---|---|---|---|
{ | { |
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