Reg Exp: The Leafcutter Ant of Computer Science

Leafcutter Ant
Leafcutter Ant

In nature few creatures demonstrate shear strength, in proportion to their size, as well as the leafcutter ant. Able to carry material around 50 times its own body weight this tiny animal are real power lifter. I personally see them as analogous to the Regular Expression (RegExp) technique in computing – small but mighty.

Another similarity ants have with RegExp is the way in which they are even more powerful when working as a collective. In my opinion its is essential that professional software engineers possess a good understanding of this technique, especially given how widespread it can be found and used.

Regular Expressions started life back in the mid-50’s with the work of  Stephen Cole Kleene and became a commonplace tool by the mid/late 1960’s. However, it would be 25 year before any form of standarisation, in the form of POSIX (Portable Operating System Interface) ISO/IEC 9945-2. Now-a-days this facility for efficient character-patten matching and string manipulation can be found in almost ever programming language from Java to .Net and even in PHP and JavaScript as well as a wealth of editors.

However, RegExp suffers significantly from its obscure syntax that engenders an air of mysticism as though written in the runic alphabet. Those of use that have spent time attempting to get to grips with the syntax find it a very powerful tool but can appear to some as wielders of a black-art. To continue with the fantasy theme: to those that find the language too challenging the string of characters might as well read “Fear ye all who proceed further for beyond lies the domain of dragons.”

To be fair, even those of us that feel comfortable working with Regular Expressions can find patterns prepared by others difficult to comprehend. But there is the trade-off. The processing power is in the parser that interprets the patters, matches and replaces strings. This means the patterns have to be in more a computer-readable than human-readable form.

From personal experience I would advocate you spend time learning how to wield the RegExp magic and become a Leafcutter Ant.

References and Useful links

  • Beginner’s Guide to Regular Expression (Regex) – Hongkiat
  • 30 Regex Code Snippets All Web Developers Should Know – Hongkiat
  • Regular Expressions: 30 Useful Tools and Resources – Hongkiat
  • Regular Expression library –
  • My personal favourite on-line RegExp resource – Debuggex
  • Learning, Building and Test resource – RegExr

Return to Articles


Leave a Reply

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

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

Google+ photo

You are commenting using your Google+ 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