No, it’s not a sanitized version of what I would say if I were to hit my thumb with a hammer.

I’ve been doing some computer programming and I’m using a lot of what are called “regular expressions” to ensure the users entered correct data to the program.

A regular expression is a template used by a “regular expression engine” (a computer program) to decide if some text presented to the “engine” matches a user supplied template.

The concept is quite powerful because the characters to check do not need to be known in advance. So, one can do things like “check to see if what was input was a specific number of letters followed by some optional characters, but the set of optional characters depend on something else within the characters being considered. but only if”… well you get the idea.

What I needed to do was to decide if a user provided the computer program with a set of characters that could be considered a valid time of day in 24 hour format.

This is not as easy as it seems. There must be four digits with an optional : character between the second and third digits. No other characters are allowed. But wait, there’s more. If the first character is a 0 or 1, then the second character can be any single digit, but if the first character is a 2, then the second character is limited to values in the range of 0-3. The third character is always limited to values in the range of 0-5 and the final character can be any single digit.

Any violations to the above criteria means the number can not be considered a valid time in 24 hour format.

It took me about 5 minutes to get the above stuff to work and I was pleased with myself.

I still can’t decide if that looks like what I said when I realized that I have a bunch of date-time calculations to do (that is a huge mess) or when I realized that “despite it being ‘only yesterday’ when I was 20…I’m over 60 years old.”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s