Wednesday, November 27, 2013

How "junior" developers can become Regex wizards

You need a Regular Expression to validate a phone number or a user's email address, so what do you do? Go onto StackOverflow and copy someone else's code and paste it into your code and be done with it? Well that may work, and if you are in an absolute pinch that can work, but what have  YOU personally really learned? Zilch.

At my job as a "junior developer" I am starting to have to use Regex (Regular Expressions) quite a bit to validate/check for certain things. I could become a "Googling wizard" but I'd rather expend the energy and effort now to become a "Regex wizard" instead. The truth is, Regular Expressions seems
daunting and intimidating, and they may be at as they get more and more complicated, however I think Regex are just different and you need to slow down and think of them as symbols and not try to rush through.

With that spirit in mind I recorded myself doing a basic Regex date string, I did it "cold turkey", so as to be authentic, and real. I did make one mistake and then fixed it, so you can see I'm quite new to this and human :-)  The point is not how much I suck, the point is to go ahead and just try to make your own Regular Expression before just "Googling the answer". I want to be a good developer one day, and I think as a young developer we should put in the extra time to try and really understand something and not just always do what is the quickest.

If you are new to Regex, is your friend. Put test strings in the box on the site and then look at the Regex "cheat sheet" on the bottom of the page when you get stuck or need a refresher. To the right you will see a blue bar that tells you if you are matching the 'test string' correctly or not which makes it easy to tell if the Regex you are making is actually correct or not.

The other thing is, DON'T RUSH, if you can't take a few minutes at work to fiddle with Regular Expressions, then make sure while eating some turkey and watching the game at Thanksgiving tomorrow that you pull out some random strings to try and match, I find it's actually really fun and not stressful if you don't pigeon hole yourself into a time crunch.

I always have my "mentor" developer at work double check my work when in doubt. NEVER put something that you are unsure of into production. Certainly on your own projects and stuff you should be able to take 5 - 10 minutes to have fun with some Regular Expressions.

Keep coding!