We all know the regular expression character classes, right? There are 12 standard classes:

[:alnum:]  [:digit:]  [:punct:]
[:alpha:]  [:graph:]  [:space:]
[:blank:]  [:lower:]  [:upper:]
[:cntrl:]  [:print:]  [:xdigit:]

But have you seen a visual representation of what these classes match? Probably not. Therefore I created a visualization that illustrates which part of the ASCII set each character class matches. Call it a cheat sheet if you like:


small version, large version

A bunch of programs that I used

Just for my own reference, in case I ever need them again, here are the one-liners I used to create this cheat sheet:

perl -nle 'printf "%08b - %08b\n", map { hex "0x".(split / /)[0], hex "0x".(split / /)[1] } $_ '
perl -nle 'printf "%03o - %03o\n", map { (split / /)[0], (split / /)[1] } $_'

And I used this perl program to generate and check the red/green matches:

use warnings;
use strict;

my $red = "\e[31m";
my $green = "\e[32m";
my $clear = "\e[0m";

my ($start, $end) = @ARGV;

die 'start or end not given' unless defined $start && defined $end;

my @classes = qw/alnum alpha blank cntrl digit graph lower print punct space upper xdigit/;

for (map { chr } $start..$end) {
    for my $class (@classes) {
        print "${green}1${clear}" if /[[:$class:]]/;
        print "${red}0${clear}" unless /[[:$class:]]/;
    }
    print "\n"
}

Credits

I was inspired to create this visualization when I saw a similar table for C's ctype.h character classification functions.

Comments

Altreus Permalink
February 26, 2013, 08:43

Save on a call to split with

map { (split / /)[0,1] }

:)

September 30, 2013, 05:21

hi, Man that is super helpful to have! Great idea, I have a bunch of char cheat-sheets I use all the time, but this is a new one. Thanks for sharing!!

February 26, 2013, 15:57

Man that is super helpful to have! Great idea, I have a bunch of char cheatsheets I use all the time, but this is a new one. Thanks for sharing!!

Justin Permalink
February 28, 2013, 17:54

I rarely see these character classes used because they tend to obscure the meaning of regular expressions because support across the standard unix tools and documentation is uneven. For example, GNU grep supports [:blank:] but the man page for GNU grep doesn't mention it. Solaris grep doesn't support character classes at all, unless you're using /usr/xpg4/bin/grep, which may. YMMV with HP-UX, AIX, IRIX/ULTRIX, etc, which all ship with their own custom implementations of regular expressions. GNU Emacs adds [:unibyte:], [:multibyte:], [:word:], [:nonascii:], [:graph:], [:ascii:], and some of those are also defined in the POSIX standard. Python may not support "standard" character classes at all-- I couldn't find any mention of them in the online docs. The actual meaning of these character classes varies as well depending on your locale environment variables. This sometimes is a good thing! Ultimately, unless you have the privilege of controlling where your regular expression is used in all cases, you have to fall back to the minimum supported syntax.

July 09, 2013, 00:29

This is very helpful! Definitely happy with this post. Thank you for sharing this.

very help. thanks

thank you very much..

July 10, 2013, 06:39

nice post

July 12, 2013, 04:34

very useful article . thanks a lot..

July 16, 2013, 14:35

What is SharePoint, Microsoft Sharepoint 2013,and Microsoft Sharepoint 2010, Sharepoint Consulting.
Best Case Studies of Document Management System implementations by Adapt India Software Private Limited,
Document Management Solution on Microsoft SharePoint to automate your business processes and facilitate exchange of documents and information internally and with your Sub Contractors with pre- defined workflows triggered with approvals, authorizations ,co-authorizations and authentications.

Sharepoint
Sharepoint 2013
Document Management
Sharepoint Server
Sharepoint Consulting
Sharepoint Designer
Sharepoint 2010
Sharepoint services
Sharepoint site
Sharepoint developer
as.

July 16, 2013, 14:35

What is SharePoint, Microsoft Sharepoint 2013,and Microsoft Sharepoint 2010, Sharepoint Consulting.
Best Case Studies of Document Management System implementations by Adapt India Software Private Limited,
Document Management Solution on Microsoft SharePoint to automate your business processes and facilitate exchange of documents and information internally and with your Sub Contractors with pre- defined workflows triggered with approvals, authorizations ,co-authorizations and authentications.

Sharepoint
Sharepoint 2013
Document Management
Sharepoint Server
Sharepoint Consulting
Sharepoint Designer
Sharepoint 2010
Sharepoint services
Sharepoint site
Sharepoint developer
as.

July 18, 2013, 05:16

holla man (y)

March 03, 2014, 17:01

wow...I am also having the same question please answer it.

March 21, 2014, 02:06

I can believe that I am also having same issues.

March 06, 2014, 04:07

Check this out man !! - Saint Patrick's Day 2014.

March 06, 2014, 04:06

Yeah man was having the same doubts for - St. Patricks Day 2014.

March 08, 2014, 18:58

Toh answer bta na...time pas kyu kr rha h :P

July 18, 2013, 05:18

Oh my goodness! an remarkable post dude. Thank you On the other hand I’m experiencing problem with ur rss . Do not know why Unable to subscribe to it. Is there any person finding identical rss challenge? Any individual who knows kindly respond. Thnkx

July 20, 2013, 19:42

Awesome Post! Thanks For Publishing.

July 23, 2013, 05:43

Those programs are great!

July 24, 2013, 02:36

great info. thanks

Eric Permalink
August 15, 2013, 14:12

Nice, Do you know if there is a Ruby script available? I'd like to compare what is different. Thanks
Eric

Anonymous Permalink
October 08, 2013, 19:49

great info. thanks
GATE 2014.
and Happy navratri 2013.

March 08, 2014, 20:02

woah..I was looking for it only..great share must say.!
how to check aadhar card status

cbse 12 Results 2014
cbse 10 result 2014 do check out my all blogs for sure and get back to me.

ipl 2014 live streaming Permalink
April 21, 2014, 20:41

i want some info regaring

IPL Live Streaming 2014
IPL Live Streaming 2014 and i hope you can find solution for this

April 24, 2014, 04:12

thanks for the info
Inter 1st year results 2014 thanks again

November 01, 2013, 17:50

The actual meaning of these character classes varies as well depending on your locale environment variables. This sometimes is a good thing! thanks for sharing.

November 01, 2013, 17:51

This is technology article learning site where are available Latest technology news,tech news,,science and technology, Education Technology, SEO tips, Mobile technology.

Allenwood Permalink
March 18, 2014, 09:26

To attain career opportunities in IT industry, pass4sure HP2-Z25 Avaya Certification is the key to unlock doors of successes and get your potential recognized. pass4sure JN0-533 levels your way to achieve your goal easily; putting less hard work and obtaining the best result in exam.

Dillon Permalink
December 25, 2013, 21:10

Being a student you should always remember to collect diverse sources where you can buy dissertations especially this here believed to do by all greatest mind of past centuries. Learn and teach at the same time while discussing any-what problem or completing any given task. Underline all strong features and strengthen insufficiency or lack of exactitude when doing a research for you or me on a daily basis.

December 29, 2013, 21:18

I rarely see these character classes used because they tend to obscure the meaning of regular expressions because support across the standard unix tools and documentation.Happy New Year 2014 Facebook SMSThanksHappy New Year 2014 Keep Sharing. Happy New Year. 2014 wishes.

February 15, 2014, 21:38

It’s highly helpful for me. Huge thumbs up for this blog post!

March 03, 2014, 17:03

Wow what a good post thanks for such a help

April 08, 2014, 07:24

Maybe that will be success

April 19, 2014, 06:03

thanks for the info IBPS Reasoning .

rishitha Permalink
April 24, 2014, 03:33

thanks intermediate results 2014 can you please check above

Leave a new comment

(why do I need your e-mail?)

(Your twitter name, if you have one. (I'm @pkrumins, btw.))

Type the first letter of your name: (just to make sure you're a human)

Please preview the comment before submitting to make sure it's OK.

Advertisements