Regular Expressions Character classes POSIX Character classes


POSIX character classes are predefined sequences for a certain set of characters.

Character classDescription
[:alpha:]Alphabetic characters
[:alnum:]Alphabetic characters and digits
[:xdigit:]Hexadecimal digits
[:blank:]Space and Tab
[:cntrl:]Control characters
[:graph:]Visible characters (anything except spaces and control characters)
[:print:]Visible characters and spaces
[:lower:]Lowercase letters
[:upper:]Uppercase letters
[:punct:]Punctuation and symbols
[:space:]All whitespace characters, including line breaks

Additional character classes my be available depending on the implementation and/or locale.

Character classDescription
[:<:]Beginning of word
[:>:]End of word
[:ascii:]ASCII Characters
[:word:]Letters, digits and underscore. Equivalent to \w

To use the inside a bracket sequence (aka. character class), you should also include the square brackets. Example:


This will match one alphabetic character.


This will match 2 characters, that are either digits or -. The following will match:

  • --
  • 11
  • -2
  • 3-

More information is available on: