[
... ]
and [^
... ]
)Lists, also called bracket expressions, are a set of one or more items. An item is a character, a character class expression, or a range expression. The syntax bits affect which kinds of items you can put in a list. We explain the last two items in subsections below. Empty lists are invalid.
A matching list matches a single character represented by one of the list items. You form a matching list by enclosing one or more items within an open-matching-list operator (represented by `[') and a close-list operator (represented by `]').
For example, `[ab]' matches either `a' or `b'. `[ad]*' matches the empty string and any string composed of just `a's and `d's in any order. Regex considers invalid a regular expression with a `[' but no matching `]'.
Nonmatching lists are similar to matching lists except that they match a single character not represented by one of the list items. You use an open-nonmatching-list operator (represented by `[^'(2)) instead of an open-matching-list operator to start a nonmatching list.
For example, `[^ab]' matches any character except `a' or `b'.
If the posix_newline
field in the pattern buffer (see section GNU Pattern Buffers is set, then nonmatching lists do not match a newline.
Most characters lose any special meaning inside a list. The special characters inside a list follow.
RE_BACKSLASH_ESCAPE_IN_LISTS
is
set.
[:
... :]
)) if the syntax bit RE_CHAR_CLASSES
is set and what
follows is a valid character class expression.
RE_CHAR_CLASSES
is set and what precedes it is an
open-character-class operator followed by a valid character class name.
-
)) if it's
not first or last in a list or the ending point of a range.
All other characters are ordinary. For example, `[.*]' matches `.' and `*'.
Go to the first, previous, next, last section, table of contents.