POSIX character classes are predefined sequences for a certain set of characters.
Character class | Description |
---|---|
[:alpha:] | Alphabetic characters |
[:alnum:] | Alphabetic characters and digits |
[:digit:] | 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 class | Description |
---|---|
[:<:] | 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:
[[:alpha:]]
This will match one alphabetic character.
[[:digit:]-]{2}
This will match 2 characters, that are either digits or -
. The following will match:
--
11
-2
3-
More information is available on: Regular-expressions.info