Regular Expressions

December 26th, 2007 by jason Leave a reply »
I have been a professional programmer for about ten years, which is to say someone has actually been paying me to write programming code since about 1997. In that time I have learned (or already learned previous to 97) the following languages, and used them in my professional endeavors: C, C++, Visual Basic, HTML, Javascript, PERL, SQL, Java, CSS, VBScript, ASP, VB.Net, C#, ASP.Net, C# 2.0, Windows Forms, Tcl, PL-SQL, .Net 3.0 (WPC, WCF and WF). I have also hobby programmed with a few languages during that time, like Ruby and Python. But in all that time, I have never really wrapped my head around regular expressions. I don't know what the deal is with me and regular expressions. I would estimate that, on average, I have found a problem that can easily be solved with regex about once a month throughout those ten years. There have probably been many more problems that I have solved in other ways the a regex could have solved, but I just did not recognize the fact at the time. No matter, I never seem to learn this powerful expression language. When I do need a regular expression, I end up going out to Google and searching for it. This is pure lazy on my part. I don't do this for SQL or C#! While I may look up references on functions or libraries, I usually try to thoroughly learn any language I am going to be using professionally. I often end up at a site like RegExLib. I don't know why I don't just go to a site like this one and actually learn regular expressions inside and out. But I don't. Its not like I don't have a basic clue about regular expressions. I have worked in VI (or VIM) and *Nix long enough to have a few expressions memorized. But still, every time I need something complicated, a searching I go! Today I needed a regex to validate that a string is a valid file path in windows. It needs to not only be able to detect a valid local file path, but a valid UNC file path. I realize that I don't really need to find one regex that will do both. I can use two regex expressions and embed them in an if/else if block in C#. The point is that I don't know how to write either one of them, so I find myself searching the web for someone else to answer this problem. I think I am going to make a resolution. The year 2008 will be the year that I finally become the master of regex! UPDATE:  I found the answer for my regex problem in the form of one, neat little expression.  Afterwards I ordered a 5 Star reviewed book on Regular Expressions from Amazon.com.  I will review the book after I have dug into it.
Advertisement

Leave a Reply

You must be logged in to post a comment.