A character set starts with '[' and ends at non-escaped ']' that is not part of a POSIX character set specifier and that does not follow immediately after '['.
The following characters have a special meaning and need to be escaped if meant literally:
A range operator, except immediately after '[', where it loses its special meaning.
If immediately after the starting '[', denotes a complement: the whole character set will be complemented. Otherwise literal '^'.
Characters for which 'isalnum' returns true.
Characters for which 'isalpha' returns true.
Characters for which 'iscntrl' returns true.
Characters for which 'isdigit' returns true.
Characters for which 'isgraph' returns true.
Characters for which 'islower' returns true.
Characters for which 'isprint' returns true.
Characters for which 'ispunct' returns true.
Characters for which 'isspace' returns true.
Characters for which 'isupper' returns true.
Characters for which 'isxdigit' returns true.
Example:
[[:xdigit:]XY]
is typically equivalent to
[0123456789ABCDEFabcdefXY]
.
It is also possible to include the predefined escaped character sets
into a newly defined one, so [\d\s]
matches digits and whitespace characters.
Also, escape sequences resulting in literals work inside character sets.