Tuesday, October 14, 2008

Regular Expressions (regex)

Still kinda surprises me the number of developers I know who are completely oblivious to the power of Regular Expressions. I'm certainly no expert on the subject but I find myself using them on quite a regular basis, probably around once a week off the top of my head.

The funny thing is that they are applicable in so many situations from Find and Replace in Visual Studio to Validating ASP.Net Form Fields to jQuery matching (though i gave up on this before i could get it to work)  to parsing comma delimeted files (j/k)  

Any Drawbacks? I find the major drawback is the fact that just about every regex provider uses a slightly different syntax, so you need to trawl the reference docs to find the right symbol. Heck, even Visual Studio's regex provider is slightly different to System.Text.RegularExpressions :S 

To combat this there are numerous cheatsheets somewhere in the pile of papers on my desk that help to remedy this situation:

And how could I forget the obligatory quote for any blog post concerning regular expressions:

Some people, when confronted with a problem, think “I know, I’ll use regular expressions.” Now they have two problems. --Jamie Zawinski, in comp.lang.emacs

No comments:

Post a Comment