Archive for October, 2005

Can you please put some comment on that Regular Expression?!

Regular expressions are one of those things on the software development world that give me nausea when I come across them. Reading something like this in code just makes me shiver:
 
^(ht|f)tp(s?)\:\/\/[0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*(:(0-9)*)*(\/?)([a-zA-Z0-9\-\.\?\,\’\/\\\+&%\$#_]*)?$
 
It seems to me like cartoon characters swearing: &$^%#&%@&$#**^&$. 
 
I just happened to run accross a little article (found at  that taught something I didn’t know about regular expression: one can put comments on them!
 
So, instead of having some cryptic code like this one:
Regex regex = new Regex(@"^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,10}\s$);
One could make the world a favor and rewrite that code like so:
Regex regex = new Regex(@"
                                            ^                 # anchor at the start
                                            (?=.*\d)      # must contain at least one numeric character
                                            (?=.*[a-z])  # must contain one lowercase character
                                            (?=.*[A-Z]) # must contain one uppercase character
                                            {8,10}         # From 8 to 10 characters in length
                                            \s                 # allows a space 
                                            $                  # anchor at the end", 
                                            RegexOptions.IgnorePatternWhitespace);
 
That way, even my little brain can understand a freakin’ regular expression.
 
Advertisements

Leave a comment

Microsoft MVP Award for 2005-2006

This is good news: last night I’ve received an email from Microsoft saying I’ve received the Microsoft MVP Award one more time. This is the 4th year in a row I receive the award, and I’m pretty happy to know that my work with the software developers’ community is still relevant.

2 Comments