Regex – character classes

A character class represents a group of characters. For example, [0-9] represents numbers, [a-z] represents all lowercase alphabets, and [A-Z] represents all uppercase alphabets.

[[:alpha:]] - represents alphabets. Translates to [a-zA- Z].
[[:alnum:]] - represents alphabets and numbers. Translates to [a-zA- Z0-9].
[[:blank:]] - represents blank spaces like tabs and spaces.
[[:cntrl:]] - represents control characters like new line, carriage return, etc.
[[:digit:]] - represents digits. Translates to [0-9].
[[:graph:]] - represents printable and visible characters.
[[:lower:]] - represents lowercase characters. Translates to [a-z].
[[:print:]] - represents printable characters.
[[:punct:]] - represents punctuation marks. Translates to [!-/:- @[-`{- ~].
[[:space:]] - represents all whitespaces. Translates to [ \t\v\f].
[[:upper:]] - represents uppercase characters. Translates to [A-Z].
[[:xdigit:]] - represents hexadecimal characters. Translates to [0-9a- fA-F]

Leave a Reply

Your email address will not be published. Required fields are marked *

1 × four =

This site uses Akismet to reduce spam. Learn how your comment data is processed.