Character classes

Character Classes

This is an alternate method of specifying a range of characters to match. With a “character class”, also called “character set”, you can tell the regex engine to match only one out of several characters.

Following are the character classes.

[:alnum:]

It matches alphabetic or numeric characters and equivalent to A-Za-z0-9.

[:alpha:]

It matches alphabetic characters and equivalent to A-Za-z.

[:lower:]

It matches lowercase alphabetic characters and equivalent to a-z.

[:upper:]

It matches uppercase alphabetic characters and equivalent to A-Z.

[:xdigit:]

It matches hexadecimal digits and equivalent to 0-9A-Fa-f.

[:digit:]

It matches digits and equivalent to 0-9.

[:blank:]

It matches a space or a tab.

[:cntrl:]

It matches control characters.

[:print:] [:graph:]

Matches characters in the range of ASCII 32 – 126.

[:space:]

It matches black space characters (space and horizontal tab).

 

Advertisements