Nov 10, 2018

POSIX character sets for Regular Expression

POSIX character sets for Regular Expression

POSIX added newer and more portable ways to search for character sets. Instead of using [a-zA-Z] you can replace 'a-zA-Z' with [:alpha:], or to be more complete. replace [a-zA-Z] with [[:alpha:]]. The advantage is that this will match international character sets. You can mix the old style and new POSIX styles, such as
grep '[1-9[:alpha:]]'
Here is the fill list
Character Group
Meaning
[:alnum:]
Alphanumeric
[:cntrl:]
Control Character
[:lower:]
Lower case character
[:space:]
Whitespace
[:alpha:]
Alphabetic
[:digit:]
Digit
[:print:]
Printable character
[:upper:]
Upper Case Character
[:blank:]
whitespace, tabs, etc.
[:graph:]
Printable and visible characters
[:punct:]
Punctuation
[:xdigit:]
Extended Digit
Some people use [[:alpha:]] as a notation.