Bracket Expression and Character Classes

Bracket expressions are a list of characters and/or character classes enclosed in brackets []. Use bracket expressions to match single characters in a list, or a range of characters in a list. If the first character of the list is the carat ^ then it matches characters that are not in the list.

For example:




a, b, or c


a through z


Any character except a, b, or c


Any alphabetic character (see below)

The following character classes must be within a bracket expression or it will be treated as a common expression.




Alphabetic characters




Alphabetic characters and numeric characters


Control character


Space and tab


All white space characters


Non-blank (not spaces, control characters, or the like)


Like [:graph:], but includes the space character


Punctuation characters


Lowercase alphabetic character


Uppercase alphabetic character


Digits allowed in a hexadecimal number (0-9a-fA-F)

For example:
  • a[[:digit:]]b matches "a0b", "a1b", ..., "a9b".

  • a[:digit:]b matches "a:b", "adb", …, "atb".

  • [[:digit:]abc] matches any digit or any of "a", "b", and "c".

  • [abc[:digit:]] matches any digit or any of "a", "b", and "c".

For a case-insensitive expression, [:lower:] and [:upper:] are equivalent to [:alpha:].